2024-01-23 16:57:15 +03:00
|
|
|
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';
|
|
|
|
|
2023-06-21 12:48:58 +03:00
|
|
|
function myErrorHandler({ error, event }: { error: any; event: NavigationEvent }) {
|
2024-03-16 03:48:30 +03:00
|
|
|
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-06-21 12:48:58 +03:00
|
|
|
}
|
2023-04-21 16:55:54 +03:00
|
|
|
|
2023-10-05 11:09:18 +03:00
|
|
|
export const handleError = handleErrorWithSentry(myErrorHandler);
|
2023-10-06 17:19:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) => {
|
2024-03-16 03:48:30 +03:00
|
|
|
logErrorToFile('Unhandled exception: ' + event?.reason + ' ' + event?.reason?.sourceURL);
|
2023-10-06 17:19:50 +03:00
|
|
|
console.log('Unhandled exception', event.reason);
|
|
|
|
originalUnhandledHandler?.bind(window)(event);
|
|
|
|
};
|