Http request exceptions captured twice in Angular 9
See original GitHub issuePackage + Version
@sentry/browser@5.15.4
Angular Version 9
Description
Implementing Sentry with Angular following the docs captures two event for http requests that return a 401 error.
I implemented a minimal version in Stackblitz
In app.component.ts a request to a protected API throws a 401 error. The console logs show the beforeSend logs having two events captures, also visible in the networks tab.
Replace the sentry init config dsn to use a different Sentry Account to see the logs in sentry.
If Sentry.captureException
is outcommented in app.module, still there is one event captured.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Communicating with backend services using HTTP - Angular
Subscribing twice results in two HTTP requests. content_copy ... HttpClient captures both kinds of errors in its HttpErrorResponse .
Read more >error handler is getting called twice angular http_interceptor
I am having two questions, when an error happens is there a way we can access request headers (so that I can get...
Read more >Introduction to error handling in Angular 7: Part 2 - Pusher
This tutorial series will introduce you to errors in JavaScript. In part two, learn about HTTP errors, how to use the `HttpClient` with...
Read more >Handling Exceptions Using the Angular HttpClient Service
We will discuss some of the best ways to manage HTTP exceptions within your app while using Angular's HttpClient service.
Read more >RxJs Error Handling: Complete Practical Guide
So without further ado, let's get started with our RxJs Error Handling deep ... HTTP response {payload: Array(9)} HTTP request completed.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lujakob thanks for letting me know. Did some debugging around this issue and it appears that
HttpClient
(which is using XHR underneath) is interacting withZone.js
in a way, where request timeouts are triggered insidesetTimeout
loop. This means that whenever it throws, oursetTimeout
instrumentation will catch it, in addition to it being passed to Angular error handler.There are 2 options. Disabling
setTimeout
instrumentation (not preferable):or filtering out
HttpErrorResponse
and migrating to@sentry/angular
that handler deals with this type of error, extracting correct data (preferable). Keep in mind that it requires Angular update to at least v9, as we need TS3.5+ for a correct compilation - https://update.angular.io/?v=8.0-9.0 :Repro:
After update to @sentry/browser@6.8.0:
After update to @sentry/angular@6.8.0 and using a correct error handler (https://github.com/getsentry/sentry-javascript/tree/master/packages/angular#errorhandler):
After update to @sentry/angular@6.8.0, using a correct error handler and using
beforeSend
filter forHttpErrorResponse
:Hope that helps! Cheers
cc @Lms24