Last active
September 24, 2020 09:54
-
-
Save raghavgarg1257/6bfafccd435c6e50db2c4e10fd5a3287 to your computer and use it in GitHub Desktop.
Angular Universal, add Error Logger like Sentry. Medium Article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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