@sneat/logging 0.27.5 → 0.27.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,8 @@ import { MultiAnalyticsService } from './multi-analytics.service';
6
6
  import { DeferredPosthogAnalyticsService } from './deferred-posthog-analytics.service';
7
7
  import { Injector } from '@angular/core';
8
8
  function getAnalyticsConfig(environmentConfig) {
9
- const useAnalytics = location.host === 'sneat.app' || location.protocol === 'https:';
9
+ const useAnalytics = typeof location !== 'undefined' &&
10
+ (location.host === 'sneat.app' || location.protocol === 'https:');
10
11
  const firebaseMeasurementId = environmentConfig.firebaseConfig?.measurementId;
11
12
  const gaMeasurementId = environmentConfig.googleAnalytics?.measurementId;
12
13
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"provide-sneat-analytics.js","sourceRoot":"","sources":["../../../../../../libs/logging/src/lib/analytics/provide-sneat-analytics.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAGhB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAY,MAAM,eAAe,CAAC;AAUnD,SAAS,kBAAkB,CACzB,iBAAqC;IAErC,MAAM,YAAY,GAChB,QAAQ,CAAC,IAAI,KAAK,WAAW,IAAI,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAElE,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,cAAc,EAAE,aAAa,CAAC;IAC9E,MAAM,eAAe,GAAG,iBAAiB,CAAC,eAAe,EAAE,aAAa,CAAC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,CAAC;oBACN,WAAW,CAAC,QAAQ,CAClB,oEAAoE,EACpE,SAAS,EACT,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CACjC,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,OAAO,IAAI,qBAAqB,CAAC,EAAE,CAAC,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Analytics } from 'firebase/analytics';\nimport {\n AnalyticsService,\n IAnalyticsService,\n IEnvironmentConfig,\n SNEAT_FIREBASE_ANALYTICS,\n} from '@sneat/core';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\nimport { FireAnalyticsService } from './fire-analytics.service';\nimport { GtagAnalyticsService } from './gtag-analytics.service';\nimport { MultiAnalyticsService } from './multi-analytics.service';\nimport { DeferredPosthogAnalyticsService } from './deferred-posthog-analytics.service';\nimport { Injector, Provider } from '@angular/core';\n\nexport interface IAnalyticsConfig {\n addPosthog?: boolean;\n addFirebaseAnalytics?: boolean;\n // GA4 measurement ID for the app's own per-domain property (the same stream\n // its marketing landing uses). When set, a gtag-based GA4 backend is added.\n googleAnalyticsMeasurementId?: string;\n}\n\nfunction getAnalyticsConfig(\n environmentConfig: IEnvironmentConfig,\n): IAnalyticsConfig {\n const useAnalytics =\n location.host === 'sneat.app' || location.protocol === 'https:';\n\n const firebaseMeasurementId = environmentConfig.firebaseConfig?.measurementId;\n const gaMeasurementId = environmentConfig.googleAnalytics?.measurementId;\n\n return {\n addPosthog: useAnalytics && !!environmentConfig.posthog?.token,\n addFirebaseAnalytics:\n useAnalytics &&\n !!firebaseMeasurementId &&\n firebaseMeasurementId !== 'G-PROVIDE_IF_NEEDED',\n googleAnalyticsMeasurementId: useAnalytics ? gaMeasurementId : undefined,\n };\n}\n\nexport function provideSneatAnalytics(\n environmentConfig: IEnvironmentConfig,\n): Provider {\n return {\n provide: AnalyticsService,\n // `Injector` rather than `SNEAT_FIREBASE_ANALYTICS` directly: listing the\n // token in `deps` would resolve it — and so initialize Firebase Analytics —\n // on every app that injects `AnalyticsService`, including the ones where\n // `addFirebaseAnalytics` is false (plain http, non-sneat.app host). Reading\n // it through the injector inside the branch below keeps initialization as\n // lazy as the pre-0.27.0 `getAnalytics(fbApp)` call it replaces.\n deps: [ErrorLogger, Injector],\n useFactory: (errorLogger: IErrorLogger, injector: Injector) => {\n const config = getAnalyticsConfig(environmentConfig);\n const as: IAnalyticsService[] = [];\n if (config?.addPosthog) {\n as.push(\n new DeferredPosthogAnalyticsService(\n environmentConfig.posthog as NonNullable<\n IEnvironmentConfig['posthog']\n >,\n errorLogger,\n ),\n );\n }\n if (config?.googleAnalyticsMeasurementId) {\n as.push(new GtagAnalyticsService(config.googleAnalyticsMeasurementId));\n }\n if (config?.addFirebaseAnalytics) {\n const analytics: Analytics | null = injector.get(\n SNEAT_FIREBASE_ANALYTICS,\n null,\n );\n if (analytics) {\n // Constructed inside this factory's injection context, so\n // FireAnalyticsService's own inject(SNEAT_FIREBASE_ANALYTICS)\n // resolves — to this same, already-instantiated instance.\n as.push(new FireAnalyticsService());\n } else {\n errorLogger.logError(\n 'addFirebaseAnalytics==true, but Firebase Analytics is not provided',\n undefined,\n { show: false, feedback: false },\n );\n }\n }\n return new MultiAnalyticsService(as);\n },\n };\n}\n"]}
1
+ {"version":3,"file":"provide-sneat-analytics.js","sourceRoot":"","sources":["../../../../../../libs/logging/src/lib/analytics/provide-sneat-analytics.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAGhB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF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oBAAoB,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC,CAAC;YACzE,CAAC;YACD,IAAI,MAAM,EAAE,oBAAoB,EAAE,CAAC;gBACjC,MAAM,SAAS,GAAqB,QAAQ,CAAC,GAAG,CAC9C,wBAAwB,EACxB,IAAI,CACL,CAAC;gBACF,IAAI,SAAS,EAAE,CAAC;oBACd,0DAA0D;oBAC1D,8DAA8D;oBAC9D,0DAA0D;oBAC1D,EAAE,CAAC,IAAI,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;gBACtC,CAAC;qBAAM,CAAC;oBACN,WAAW,CAAC,QAAQ,CAClB,oEAAoE,EACpE,SAAS,EACT,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CACjC,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,OAAO,IAAI,qBAAqB,CAAC,EAAE,CAAC,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Analytics } from 'firebase/analytics';\nimport {\n AnalyticsService,\n IAnalyticsService,\n IEnvironmentConfig,\n SNEAT_FIREBASE_ANALYTICS,\n} from '@sneat/core';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\nimport { FireAnalyticsService } from './fire-analytics.service';\nimport { GtagAnalyticsService } from './gtag-analytics.service';\nimport { MultiAnalyticsService } from './multi-analytics.service';\nimport { DeferredPosthogAnalyticsService } from './deferred-posthog-analytics.service';\nimport { Injector, Provider } from '@angular/core';\n\nexport interface IAnalyticsConfig {\n addPosthog?: boolean;\n addFirebaseAnalytics?: boolean;\n // GA4 measurement ID for the app's own per-domain property (the same stream\n // its marketing landing uses). When set, a gtag-based GA4 backend is added.\n googleAnalyticsMeasurementId?: string;\n}\n\nfunction getAnalyticsConfig(\n environmentConfig: IEnvironmentConfig,\n): IAnalyticsConfig {\n const useAnalytics =\n typeof location !== 'undefined' &&\n (location.host === 'sneat.app' || location.protocol === 'https:');\n\n const firebaseMeasurementId = environmentConfig.firebaseConfig?.measurementId;\n const gaMeasurementId = environmentConfig.googleAnalytics?.measurementId;\n\n return {\n addPosthog: useAnalytics && !!environmentConfig.posthog?.token,\n addFirebaseAnalytics:\n useAnalytics &&\n !!firebaseMeasurementId &&\n firebaseMeasurementId !== 'G-PROVIDE_IF_NEEDED',\n googleAnalyticsMeasurementId: useAnalytics ? gaMeasurementId : undefined,\n };\n}\n\nexport function provideSneatAnalytics(\n environmentConfig: IEnvironmentConfig,\n): Provider {\n return {\n provide: AnalyticsService,\n // `Injector` rather than `SNEAT_FIREBASE_ANALYTICS` directly: listing the\n // token in `deps` would resolve it — and so initialize Firebase Analytics —\n // on every app that injects `AnalyticsService`, including the ones where\n // `addFirebaseAnalytics` is false (plain http, non-sneat.app host). Reading\n // it through the injector inside the branch below keeps initialization as\n // lazy as the pre-0.27.0 `getAnalytics(fbApp)` call it replaces.\n deps: [ErrorLogger, Injector],\n useFactory: (errorLogger: IErrorLogger, injector: Injector) => {\n const config = getAnalyticsConfig(environmentConfig);\n const as: IAnalyticsService[] = [];\n if (config?.addPosthog) {\n as.push(\n new DeferredPosthogAnalyticsService(\n environmentConfig.posthog as NonNullable<\n IEnvironmentConfig['posthog']\n >,\n errorLogger,\n ),\n );\n }\n if (config?.googleAnalyticsMeasurementId) {\n as.push(new GtagAnalyticsService(config.googleAnalyticsMeasurementId));\n }\n if (config?.addFirebaseAnalytics) {\n const analytics: Analytics | null = injector.get(\n SNEAT_FIREBASE_ANALYTICS,\n null,\n );\n if (analytics) {\n // Constructed inside this factory's injection context, so\n // FireAnalyticsService's own inject(SNEAT_FIREBASE_ANALYTICS)\n // resolves — to this same, already-instantiated instance.\n as.push(new FireAnalyticsService());\n } else {\n errorLogger.logError(\n 'addFirebaseAnalytics==true, but Firebase Analytics is not provided',\n undefined,\n { show: false, feedback: false },\n );\n }\n }\n return new MultiAnalyticsService(as);\n },\n };\n}\n"]}
@@ -23,6 +23,11 @@ export class ErrorLoggerService {
23
23
  console.error('ErrorLoggerService.logError: arguments look swapped — got a string for `e` and a non-string for `message`. Expected logError(error: unknown, message?: string, options?).', { e, message });
24
24
  }
25
25
  console.error(`ErrorLoggerService.logError: ${message || 'Error'}:`, e, '; Logging options:', options);
26
+ // Server rendering must record the error without invoking browser-only
27
+ // Sentry feedback UI or Ionic toasts.
28
+ if (typeof window === 'undefined') {
29
+ return;
30
+ }
26
31
  if (e === true || e === false) {
27
32
  try {
28
33
  // noinspection ExceptionCaughtLocallyJS
@@ -1 +1 @@
1
- {"version":3,"file":"error-logger.service.js","sourceRoot":"","sources":["../../../../../libs/logging/src/lib/error-logger.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;;;AAGrE,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAGvC,MAAM,OAAO,kBAAkB;IAC7B,YAAyC,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;QAEzD,oBAAe,GAC7B,CAAC,OAAgB,EAAE,OAA0B,EAAE,EAAE,CAAC,CAAC,CAAU,EAAE,EAAE,CAC/D,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAEvB,aAAQ,GAAG,CACzB,CAAU,EACV,OAAgB,EAChB,OAA0B,EACpB,EAAE;YACR,uEAAuE;YACvE,wEAAwE;YACxE,sEAAsE;YACtE,wEAAwE;YACxE,uEAAuE;YACvE,oEAAoE;YACpE,+CAA+C;YAC/C,IACE,OAAO,CAAC,KAAK,QAAQ;gBACrB,OAAO,KAAK,SAAS;gBACrB,OAAO,OAAO,KAAK,QAAQ,EAC3B,CAAC;gBACD,OAAO,CAAC,KAAK,CACX,2KAA2K,EAC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nB,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,OAAO;oBACb,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,GAAG,EAAE,CACZ,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CACzC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,gCAAgC,EAAE;wBACjD,IAAI,EAAE,KAAK;qBACZ,CAAC,CACH;iBACJ;aACF;YACD,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,sBAAsB;YAC9B,QAAQ,EAAE,KAAK;SAChB,CAAC;aACD,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CACd,KAAK;aACF,OAAO,EAAE;aACT,KAAK,CACJ,IAAI,CAAC,eAAe,CAClB,6CAA6C,EAC7C,EAAE,IAAI,EAAE,KAAK,EAAE,CAChB,CACF,CACJ;aACA,KAAK,CACJ,IAAI,CAAC,eAAe,CAAC,8CAA8C,EAAE;YACnE,IAAI,EAAE,KAAK;SACZ,CAAC,CACH,CAAC;IACN,CAAC;8GAzIU,kBAAkB;kHAAlB,kBAAkB;;2FAAlB,kBAAkB;kBAD9B,UAAU;;0BAEI,QAAQ","sourcesContent":["import { HttpErrorResponse } from '@angular/common/http';\nimport { Injectable, Optional } from '@angular/core';\nimport { ToastController } from '@ionic/angular';\nimport { captureException, showReportDialog } from '@sentry/angular';\nimport { IErrorLogger, ILogErrorOptions } from '@sneat/core';\n\nconst defaultErrorToastDuration = 7000;\n\n@Injectable()\nexport class ErrorLoggerService implements IErrorLogger {\n constructor(@Optional() private readonly toastController: ToastController) {}\n\n public readonly logErrorHandler =\n (message?: string, options?: ILogErrorOptions) => (e: unknown) =>\n this.logError(e, message, options);\n\n public readonly logError = (\n e: unknown,\n message?: string,\n options?: ILogErrorOptions,\n ): void => {\n // logError(e, message, options) is easy to call with `e` and `message`\n // swapped (both a string and unknown/undefined are type-legal in either\n // slot, so the compiler can't catch it). A string `e` combined with a\n // non-string `message` is the tell-tale sign of that swap — e.g. a real\n // Error/HttpErrorResponse landing in `message`, where its fields (like\n // HttpErrorResponse's server-provided message) are never read. Warn\n // loudly so it isn't silently swallowed again.\n if (\n typeof e === 'string' &&\n message !== undefined &&\n typeof message !== 'string'\n ) {\n console.error(\n 'ErrorLoggerService.logError: arguments look swapped — got a string for `e` and a non-string for `message`. Expected logError(error: unknown, message?: string, options?).',\n { e, message },\n );\n }\n console.error(\n `ErrorLoggerService.logError: ${message || 'Error'}:`,\n e,\n '; Logging options:',\n options,\n );\n if (e === true || e === false) {\n try {\n // noinspection ExceptionCaughtLocallyJS\n throw new Error(`got boolean value as an error: ${e}: ${message}`);\n } catch (ex) {\n console.error('Argument exception at logError():', ex, options);\n return;\n }\n }\n if (options?.report === undefined || options.report) {\n if (window.location.hostname !== 'localhost') {\n try {\n const eventId = message\n ? captureException(message, { originalException: e })\n : captureException(e);\n\n // console.log('Captured error by Sentry with eventId:', eventId);\n if (options?.feedback === undefined || options.feedback) {\n showReportDialog({ eventId });\n }\n } catch (ex) {\n console.error(\n 'Sentry failed to capture or show error report dialog',\n ex,\n );\n }\n }\n }\n if (options?.show || options?.show === undefined) {\n this.showError(e, options?.showDuration);\n }\n return; // return message ? { error: e, message } : e;\n };\n\n public showError(e: unknown, duration?: number): void {\n let clientMessage: string | undefined;\n\n if ((e as { message?: string }).message) {\n clientMessage =\n (clientMessage &&\n `${clientMessage}: ${(e as { message?: string }).message}`) ||\n (e as { message?: string }).message;\n } else if (!clientMessage) {\n clientMessage = (e as object).toString();\n }\n if (!clientMessage) {\n throw new Error('showError() have not received a message to display');\n }\n if (duration && duration < 0) {\n throw new Error('showError received negative duration');\n }\n\n let message = clientMessage;\n\n let serverMessage: string | undefined;\n if (e instanceof HttpErrorResponse) {\n const e2 = e as HttpErrorResponse;\n serverMessage = e2.error?.error?.message;\n if (serverMessage) {\n message += `.\\n\\nServer returned error message: ${serverMessage}`;\n }\n }\n if (!this.toastController) {\n console.warn('ToastController not available, cannot show error toast');\n return;\n }\n this.toastController\n .create({\n message,\n duration: duration || defaultErrorToastDuration,\n keyboardClose: true,\n buttons: [\n {\n icon: 'close',\n side: 'end',\n handler: () =>\n this.toastController.dismiss().catch((e) =>\n this.logError(e, 'Failed to dismiss error dialog', {\n show: false,\n }),\n ),\n },\n ],\n color: 'danger',\n header: 'Something went wrong',\n position: 'top',\n })\n .then((toast) =>\n toast\n .present()\n .catch(\n this.logErrorHandler(\n 'Failed to present toast with error message:',\n { show: false },\n ),\n ),\n )\n .catch(\n this.logErrorHandler('Failed to create a toast with error message:', {\n show: false,\n }),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"error-logger.service.js","sourceRoot":"","sources":["../../../../../libs/logging/src/lib/error-logger.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;;;AAGrE,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAGvC,MAAM,OAAO,kBAAkB;IAC7B,YAAyC,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;QAEzD,oBAAe,GAC7B,CAAC,OAAgB,EAAE,OAA0B,EAAE,EAAE,CAAC,CAAC,CAAU,EAAE,EAAE,CAC/D,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAEvB,aAAQ,GAAG,CACzB,CAAU,EACV,OAAgB,EAChB,OAA0B,EACpB,EAAE;YACR,uEAAuE;YACvE,wEAAwE;YACxE,sEAAsE;YACtE,wEAAwE;YACxE,uEAAuE;YACvE,oEAAoE;YACpE,+CAA+C;YAC/C,IACE,OAAO,CAAC,KAAK,QAAQ;gBACrB,OAAO,KAAK,SA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1B,OAAO,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;YACvE,OAAO;QACT,CAAC;QACD,IAAI,CAAC,eAAe;aACjB,MAAM,CAAC;YACN,OAAO;YACP,QAAQ,EAAE,QAAQ,IAAI,yBAAyB;YAC/C,aAAa,EAAE,IAAI;YACnB,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,OAAO;oBACb,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,GAAG,EAAE,CACZ,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CACzC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,gCAAgC,EAAE;wBACjD,IAAI,EAAE,KAAK;qBACZ,CAAC,CACH;iBACJ;aACF;YACD,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,sBAAsB;YAC9B,QAAQ,EAAE,KAAK;SAChB,CAAC;aACD,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CACd,KAAK;aACF,OAAO,EAAE;aACT,KAAK,CACJ,IAAI,CAAC,eAAe,CAClB,6CAA6C,EAC7C,EAAE,IAAI,EAAE,KAAK,EAAE,CAChB,CACF,CACJ;aACA,KAAK,CACJ,IAAI,CAAC,eAAe,CAAC,8CAA8C,EAAE;YACnE,IAAI,EAAE,KAAK;SACZ,CAAC,CACH,CAAC;IACN,CAAC;8GA9IU,kBAAkB;kHAAlB,kBAAkB;;2FAAlB,kBAAkB;kBAD9B,UAAU;;0BAEI,QAAQ","sourcesContent":["import { HttpErrorResponse } from '@angular/common/http';\nimport { Injectable, Optional } from '@angular/core';\nimport { ToastController } from '@ionic/angular';\nimport { captureException, showReportDialog } from '@sentry/angular';\nimport { IErrorLogger, ILogErrorOptions } from '@sneat/core';\n\nconst defaultErrorToastDuration = 7000;\n\n@Injectable()\nexport class ErrorLoggerService implements IErrorLogger {\n constructor(@Optional() private readonly toastController: ToastController) {}\n\n public readonly logErrorHandler =\n (message?: string, options?: ILogErrorOptions) => (e: unknown) =>\n this.logError(e, message, options);\n\n public readonly logError = (\n e: unknown,\n message?: string,\n options?: ILogErrorOptions,\n ): void => {\n // logError(e, message, options) is easy to call with `e` and `message`\n // swapped (both a string and unknown/undefined are type-legal in either\n // slot, so the compiler can't catch it). A string `e` combined with a\n // non-string `message` is the tell-tale sign of that swap — e.g. a real\n // Error/HttpErrorResponse landing in `message`, where its fields (like\n // HttpErrorResponse's server-provided message) are never read. Warn\n // loudly so it isn't silently swallowed again.\n if (\n typeof e === 'string' &&\n message !== undefined &&\n typeof message !== 'string'\n ) {\n console.error(\n 'ErrorLoggerService.logError: arguments look swapped — got a string for `e` and a non-string for `message`. Expected logError(error: unknown, message?: string, options?).',\n { e, message },\n );\n }\n console.error(\n `ErrorLoggerService.logError: ${message || 'Error'}:`,\n e,\n '; Logging options:',\n options,\n );\n // Server rendering must record the error without invoking browser-only\n // Sentry feedback UI or Ionic toasts.\n if (typeof window === 'undefined') {\n return;\n }\n if (e === true || e === false) {\n try {\n // noinspection ExceptionCaughtLocallyJS\n throw new Error(`got boolean value as an error: ${e}: ${message}`);\n } catch (ex) {\n console.error('Argument exception at logError():', ex, options);\n return;\n }\n }\n if (options?.report === undefined || options.report) {\n if (window.location.hostname !== 'localhost') {\n try {\n const eventId = message\n ? captureException(message, { originalException: e })\n : captureException(e);\n\n // console.log('Captured error by Sentry with eventId:', eventId);\n if (options?.feedback === undefined || options.feedback) {\n showReportDialog({ eventId });\n }\n } catch (ex) {\n console.error(\n 'Sentry failed to capture or show error report dialog',\n ex,\n );\n }\n }\n }\n if (options?.show || options?.show === undefined) {\n this.showError(e, options?.showDuration);\n }\n return; // return message ? { error: e, message } : e;\n };\n\n public showError(e: unknown, duration?: number): void {\n let clientMessage: string | undefined;\n\n if ((e as { message?: string }).message) {\n clientMessage =\n (clientMessage &&\n `${clientMessage}: ${(e as { message?: string }).message}`) ||\n (e as { message?: string }).message;\n } else if (!clientMessage) {\n clientMessage = (e as object).toString();\n }\n if (!clientMessage) {\n throw new Error('showError() have not received a message to display');\n }\n if (duration && duration < 0) {\n throw new Error('showError received negative duration');\n }\n\n let message = clientMessage;\n\n let serverMessage: string | undefined;\n if (e instanceof HttpErrorResponse) {\n const e2 = e as HttpErrorResponse;\n serverMessage = e2.error?.error?.message;\n if (serverMessage) {\n message += `.\\n\\nServer returned error message: ${serverMessage}`;\n }\n }\n if (!this.toastController) {\n console.warn('ToastController not available, cannot show error toast');\n return;\n }\n this.toastController\n .create({\n message,\n duration: duration || defaultErrorToastDuration,\n keyboardClose: true,\n buttons: [\n {\n icon: 'close',\n side: 'end',\n handler: () =>\n this.toastController.dismiss().catch((e) =>\n this.logError(e, 'Failed to dismiss error dialog', {\n show: false,\n }),\n ),\n },\n ],\n color: 'danger',\n header: 'Something went wrong',\n position: 'top',\n })\n .then((toast) =>\n toast\n .present()\n .catch(\n this.logErrorHandler(\n 'Failed to present toast with error message:',\n { show: false },\n ),\n ),\n )\n .catch(\n this.logErrorHandler('Failed to create a toast with error message:', {\n show: false,\n }),\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sneat/logging",
3
- "version": "0.27.5",
3
+ "version": "0.27.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },