I am using Sentry and Angular.
When an error happens, and after it has been send, I would like to redirect users to an error page.
But I don’t find a proper way.
- Redirect in
beforeSend
is not ok as error has not been sent, and a redirection would break it. - implement a custom
errorHandler
is a good solution, but I do not want to manually copy the already existing SentryErrorHandler. So I tried extending it, but since this service is injectable, doing a new
@Injectable({ providedIn: 'root' })
class SentryCustomErrorHandler extends SentryErrorHandler {
constructor(@Inject('errorConfig') config: ErrorHandlerOptions) {
super(config);
}
handleError(error: unknown): void {
super.handleError(error);
window.location.href = '/error';
}
}
/**
* Factory function that creates an instance of a preconfigured ErrorHandler provider.
*/
function createSentryCustomErrorHandler(config?: ErrorHandlerOptions): SentryErrorHandler {
return new SentryCustomErrorHandler(config);
}
export { createSentryCustomErrorHandler, SentryCustomErrorHandler };
with another Injectable
breaks angular.
I can’t find a way to execute code after
an error is sent…