Skip to content

Commit

Permalink
Supress 'Perhaps the DotNetObjectReference instance was already dispo…
Browse files Browse the repository at this point in the history
…sed' error notifications
  • Loading branch information
myieye committed Jan 20, 2025
1 parent c779994 commit ac11183
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion frontend/viewer/src/lib/errors/global-errors.ts
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);
});
}

0 comments on commit ac11183

Please sign in to comment.