-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supress 'Perhaps the DotNetObjectReference instance was already dispo…
…sed' error notifications
- Loading branch information
Showing
1 changed file
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
import {AppNotification} from '$lib/notifications/notifications'; | ||
|
||
function getPromiseRejectionMessage(event: PromiseRejectionEvent): string { | ||
if (event.reason instanceof Error) { | ||
return event.reason.message; | ||
} else if (typeof event.reason === 'string') { | ||
return event.reason; | ||
} else { | ||
return 'Unknown error'; | ||
} | ||
} | ||
|
||
function suppressPromiseRejectionNotification(message: string): boolean { | ||
if (message.includes('Perhaps the DotNetObjectReference instance was already disposed')) return true; | ||
return false; | ||
} | ||
|
||
export function setupGlobalErrorHandlers() { | ||
window.addEventListener('error', (event: ErrorEvent) => { | ||
console.error('Global error', event); | ||
AppNotification.display(event.message, 'error', undefined); | ||
}); | ||
|
||
window.addEventListener('unhandledrejection', (event: PromiseRejectionEvent) => { | ||
AppNotification.display(event.reason as string, 'error', undefined); | ||
const message = getPromiseRejectionMessage(event); | ||
console.error('Global unhandled rejection', message, event); | ||
|
||
if (suppressPromiseRejectionNotification(message)) return; | ||
AppNotification.display(message, 'error', undefined); | ||
}); | ||
} |