-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new behavior for global ErrorHandler and uncaught errors from promises #27840
Comments
Same behavior (problem?) here, but using Resolve. If inside this.http.get<Holiday>(`/some-404-returning-url/${id}`).subscribe(); the Versions:
|
It appears to be an issue with the type of error coming out of Zone.js changing... Here's a small stackblitz repro NOTE that it does this with any rejected promise. |
Currently, in |
This one has been reverted because some test failed, will try in the next version |
This issue is still present in Angular 8 as far as I can see. We're currently on version 8.2.14. Is there a fix ready, was this issue forgotten or will it not be fixed by design? |
@didii just do this and then your handler is future proof
|
The same problem here (Angular 8.2.14) Maybe this could help someone:
|
Seeing as how this is still open, would the angular team welcome a little note in the docs simply explaining it? |
the previous PR was reverted, I will create a new PR to fix this issue. |
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `reject` property equals to the `originalError`, and the message will be `Uncaught (in promise): testError...`. You can disable this wrapping behavior by defining a global configuraiton ` __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `reject` property equals to the `originalError`, and the message will be `Uncaught (in promise): testError...`. You can disable this wrapping behavior by defining a global configuraiton ` __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `reject` property equals to the `originalError`, and the message will be `Uncaught (in promise): testError...`. You can disable this wrapping behavior by defining a global configuraiton ` __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `reject` property equals to the `originalError`, and the message will be `Uncaught (in promise): testError...`. You can disable this wrapping behavior by defining a global configuraiton ` __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `reject` property equals to the `originalError`, and the message will be `Uncaught (in promise): testError...`. You can disable this wrapping behavior by defining a global configuraiton ` __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `reject` property equals to the `originalError`, and the message will be `Uncaught (in promise): testError...`. You can disable this wrapping behavior by defining a global configuraiton ` __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `reject` property equals to the `originalError`, and the message will be `Uncaught (in promise): testError...`. You can disable this wrapping behavior by defining a global configuraiton ` __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `reject` property equals to the `originalError`, and the message will be `Uncaught (in promise): testError...`. You can disable this wrapping behavior by defining a global configuraiton ` __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `rejection` property equals to the original error, and the message will be `Uncaught (in promise): testError....`, You can disable this wrapping behavior by defining a global configuraiton `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
…ght promise rejection Close angular#27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `rejection` property equals to the original error, and the message will be `Uncaught (in promise): testError....`, You can disable this wrapping behavior by defining a global configuraiton `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 bug report
Affected Package
Well I thought this was zone.js wrapping the errors, but I rolled zone back only zone and it didn't change.Is this a regression?
Yes, the previous version in which this bug was not present was 5.xDescription
Previously, unhandled errors from promises were handed to a custom error handler unchanged. But now, it seems the error is wrapped and you need to unwrap it to get the real error that's sitting on the "rejection" property of the error.
The docs make no mention of this here https://angular.io/api/core/ErrorHandler and neither does any googling surprisingly.
I noticed this only after upgrading from angular 5 to angular 7 and one of my e2e tests that relied on my general error handler started failing.
The only workaround I found was to have something like this at the top of the error handler's handleError() method like this:
but...
Either way, if this was some kind of intentional feature, it's definitely a gotcha that I think should be mentioned (with the RIGHT way to handle it) in the doc link I pasted.
🔬 Minimal Reproduction
inject HttpClient
await this.http.get('/some-404-returning-url').toPromise();
🔥 Exception or Error
EXPECTED: error handler works, gets the HttpErrorResponse, and shows the snackbar
ACTUAL: the HttpErrorResponse is on error.rejection instead of right on error.
🌍 Your Environment
Angular Version:
Anything else relevant?
The text was updated successfully, but these errors were encountered: