Skip to content

Instantly share code, notes, and snippets.

@raghavgarg1257
Last active September 24, 2020 09:54
Show Gist options
  • Save raghavgarg1257/6bfafccd435c6e50db2c4e10fd5a3287 to your computer and use it in GitHub Desktop.
Save raghavgarg1257/6bfafccd435c6e50db2c4e10fd5a3287 to your computer and use it in GitHub Desktop.
Angular Universal, add Error Logger like Sentry. Medium Article
import { ErrorHandler } from '@angular/core';
import { environment } from '../environments/environment';
export class ErrorLogger implements ErrorHandler {
static initWith(sentry: any) {
return () => new ErrorLogger(sentry);
}
constructor(private sentry: any) {
if (environment.production) {
this.sentry.init({ dsn: environment.sentryDsn });
}
}
handleError(error: any): void {
if (environment.production) {
this.sentry.captureException(error.originalError || error);
}
throw error; // for default behaviour rather than silentely dying
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment