* @param event {PromiseRejectionEvent|ErrorEvent}
(event)
| 37 | * @param event {PromiseRejectionEvent|ErrorEvent} |
| 38 | */ |
| 39 | function handler(event) { |
| 40 | var error; |
| 41 | |
| 42 | if ('error' in event) { |
| 43 | error = |
| 44 | event.error || |
| 45 | (event.message === 'Script error.' |
| 46 | ? new SyntaxError(event.message) |
| 47 | : new Error(event.message)); |
| 48 | } else { |
| 49 | error = event.reason; |
| 50 | } |
| 51 | |
| 52 | console.error('unhandled unrecoverable error', error); |
| 53 | |
| 54 | var shouldCache = |
| 55 | // syntax error |
| 56 | error && error instanceof SyntaxError; |
| 57 | |
| 58 | if (!shouldCache) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | event.stopImmediatePropagation(); |
| 63 | showGlobalErrorPage(); |
| 64 | } |
| 65 | |
| 66 | function registerGlobalErrorHandler() { |
| 67 | if (typeof document !== 'undefined') { |
nothing calls this directly
no test coverage detected