gitbutler/app/src/hooks.client.ts

26 lines
1.1 KiB
TypeScript
Raw Normal View History

import { handleErrorWithSentry } from '@sentry/sveltekit';
2024-02-29 21:28:45 +03:00
import { error as logErrorToFile } from 'tauri-plugin-log-api';
2023-04-21 16:55:54 +03:00
import type { NavigationEvent } from '@sveltejs/kit';
function myErrorHandler({ error, event }: { error: any; event: NavigationEvent }) {
console.error(error.message + '\n' + error.stack);
logErrorToFile(error.toString());
2023-04-21 16:55:54 +03:00
console.error('An error occurred on the client side:', error, event);
}
2023-04-21 16:55:54 +03:00
export const handleError = handleErrorWithSentry(myErrorHandler);
/**
* This is not an ideal way of handling unhandled errors, but it's what we have at the moment. The
* main reason for adding this is that it gives us better stack traces when promises throw errors
* in reactive statements.
*
* See: https://github.com/sveltejs/rfcs/pull/46
*/
const originalUnhandledHandler = window.onunhandledrejection;
window.onunhandledrejection = (event: PromiseRejectionEvent) => {
logErrorToFile('Unhandled exception: ' + event?.reason + ' ' + event?.reason?.sourceURL);
console.log('Unhandled exception', event.reason);
originalUnhandledHandler?.bind(window)(event);
};