Title: new behavior for global ErrorHandler and uncaught errors from promises · Issue #27840 · angular/angular · GitHub
Open Graph Title: new behavior for global ErrorHandler and uncaught errors from promises · Issue #27840 · angular/angular
X Title: new behavior for global ErrorHandler and uncaught errors from promises · Issue #27840 · angular/angular
Description: 🐞 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.x Descripti...
Open Graph Description: 🐞 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 th...
X Description: 🐞 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 whic...
Opengraph URL: https://github.com/angular/angular/issues/27840
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"new behavior for global ErrorHandler and uncaught errors from promises","articleBody":"\u003c!--🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅\r\n\r\nOh hi there! 😄\r\n\r\nTo expedite issue processing please search open and closed issues before submitting a new one.\r\nExisting issues often contain information about workarounds, resolution, or progress updates.\r\n\r\n🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅-->\r\n\r\n\r\n# 🐞 bug report\r\n\r\n### Affected Package\r\n\u003c!-- Can you pin-point one or more @angular/* packages as the source of the bug? -->\r\n\u003c!-- ✍️edit: --> Well I thought this was zone.js wrapping the errors, but I rolled zone back only zone and it didn't change.\r\n\r\n\r\n### Is this a regression?\r\n\r\n\u003c!-- Did this behavior use to work in the previous version? -->\r\n\u003c!-- ✍️--> Yes, the previous version in which this bug was not present was 5.x\r\n\r\n### Description\r\n\r\n\u003c!-- ✍️-->\r\n\r\nPreviously, 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.\r\n\r\nThe docs make no mention of this here https://angular.io/api/core/ErrorHandler and neither does any googling surprisingly.\r\n\r\nI 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.\r\n\r\nThe only workaround I found was to have something like this at the top of the error handler's handleError() method like this:\r\n\r\n```typescript\r\n while(error.rejection) {\r\n error = error.rejection;\r\n }\r\n\r\n```\r\nbut...\r\n\r\n1. I'm quite sure there's a better way - now I have to type error as any\r\n2. I'm not sure if there are any other situations that will require unwrapping (e.g. from observables?).\r\n\r\nEither 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.\r\n\r\n## 🔬 Minimal Reproduction\r\n\u003c!--\r\nPlease create and share minimal reproduction of the issue starting with this template: https://stackblitz.com/fork/angular-issue-repro2\r\n-->\r\n\u003c!-- ✍️--> \r\n\r\n1. follow the docs and implement a global error handler and try to handle unhandled requests uniformly - something like this:\r\n\r\n```typescript\r\n@Injectable()\r\nexport class SpiffyErrorHandlerService implements ErrorHandler {\r\n constructor(private injector: Injector, private snackBar: MatSnackBar) {}\r\n public handleError(error: Error) {\r\n if (error instanceof HttpErrorResponse) {\r\n if (error.status === 401) {\r\n this.snackBar.open(\r\n 'Oops. It looks like you tried to access a logged-in resource while logged out. Please log in again.',\r\n '',\r\n { duration: 3000 }\r\n );\r\n }\r\n }\r\n}\r\n```\r\n\r\n2. inject HttpClient\r\n\r\n3. await this.http.get('/some-404-returning-url').toPromise();\r\n\r\n\u003c!--\r\nIf StackBlitz is not suitable for reproduction of your issue, please create a minimal GitHub repository with the reproduction of the issue. Share the link to the repo below along with step-by-step instructions to reproduce the problem, as well as expected and actual behavior.\r\n\r\nIssues that don't have enough info and can't be reproduced will be closed.\r\n\r\nYou can read more about issue submission guidelines here: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-submitting-an-issue\r\n-->\r\n\r\n## 🔥 Exception or Error\r\n\r\nEXPECTED: error handler works, gets the HttpErrorResponse, and shows the snackbar\r\nACTUAL: the HttpErrorResponse is on error.rejection instead of right on error.\r\n\r\n## 🌍 Your Environment\r\n\r\n**Angular Version:**\r\n\u003cpre>\u003ccode>\r\n\u003c!-- run `ng version` and paste output below -->\r\n\u003c!-- ✍️-->\r\n\r\nAngular CLI: 7.1.2\r\nNode: 10.14.2\r\nOS: linux x64\r\nAngular: 7.1.3\r\n... animations, common, compiler, compiler-cli, core, forms\r\n... http, language-service, platform-browser\r\n... platform-browser-dynamic, router, service-worker\r\n\r\nPackage Version\r\n-----------------------------------------------------------\r\n@angular-devkit/architect 0.10.7\r\n@angular-devkit/build-angular 0.10.7\r\n@angular-devkit/build-optimizer 0.10.7\r\n@angular-devkit/build-webpack 0.10.7\r\n@angular-devkit/core 7.0.7\r\n@angular-devkit/schematics 7.1.2\r\n@angular/cdk 7.1.1\r\n@angular/cli 7.1.2\r\n@angular/flex-layout 7.0.0-beta.19\r\n@angular/material 7.1.1\r\n@ngtools/webpack 7.0.7\r\n@schematics/angular 7.1.2\r\n@schematics/update 0.11.2\r\nrxjs 6.3.3\r\ntypescript 3.1.6\r\nwebpack 4.19.1\r\n \r\n\u003c/code>\u003c/pre>\r\n\r\n**Anything else relevant?**\r\n\u003c!-- ✍️Is this a browser specific issue? If so, please specify the browser and version. -->\r\n\r\n\u003c!-- ✍️Do any of these matter: operating system, IDE, package manager, HTTP server, ...? If so, please mention it below. -->\r\n","author":{"url":"https://github.com/trycatchal","@type":"Person","name":"trycatchal"},"datePublished":"2018-12-26T21:47:22Z","url":"https://github.com/angular/angular/issues/27840"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4b4c76f7-95de-226a-5a0f-5df7d3ef1aae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC52:28815B:1901EB8:2134CDB:6B014BC9 |
| html-safe-nonce | e318f12b6d9320a3e4fa2729104b3f45cad8cff37233b67c7bdc4eaa9c06ac86 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzUyOjI4ODE1QjoxOTAxRUI4OjIxMzRDREI6NkIwMTRCQzkiLCJ2aXNpdG9yX2lkIjoiODY2NDc3NjcyMjUwNTM1NDE4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 999edc8d87bd10f29dc1347f8fb90fa2a22adcfb70302b0225005da78f4d4aa5 |
| hovercard-subject-tag | issue:394246781 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/27840/issue_layout |
| twitter:image | https://opengraph.githubassets.com/246720fcf11bbf6a02b00a675f0c003021878e3cd6883ae46afcaef7232b7dd9/angular/angular/issues/27840 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/246720fcf11bbf6a02b00a675f0c003021878e3cd6883ae46afcaef7232b7dd9/angular/angular/issues/27840 |
| og:image:alt | 🐞 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 th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trycatchal |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width