From 6435719a1c3d1e7fc03883ba715ed0983bfa8aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojtech=20Ma=C5=A1ek?= Date: Mon, 14 Aug 2023 14:13:22 +0200 Subject: [PATCH] refactor(ng-universal-express): icon loader log errors --- .../src/app/icon-load.ssr.strategy.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/projects/ng-universal-express/src/app/icon-load.ssr.strategy.ts b/projects/ng-universal-express/src/app/icon-load.ssr.strategy.ts index 0821cd44..93142f55 100644 --- a/projects/ng-universal-express/src/app/icon-load.ssr.strategy.ts +++ b/projects/ng-universal-express/src/app/icon-load.ssr.strategy.ts @@ -1,12 +1,20 @@ import { Injectable } from '@angular/core'; import { SvgLoadStrategy } from '@push-based/ngx-fast-svg'; -import { readFileSync } from 'node:fs'; +import { readFile } from 'node:fs'; import { resolve } from 'node:path'; -import { Observable, of } from 'rxjs'; +import { Observable } from 'rxjs'; @Injectable() export class IconLoadStrategySsr implements SvgLoadStrategy { load(url: string): Observable { - return of(readFileSync(resolve(url), 'utf8')); + return new Observable((observer) => { + readFile(resolve(url), { encoding: 'utf8' }, (error, data) => { + if (error) { + observer.error(error); + } else { + observer.next(data); + } + }); + }); } }