paste69/src/hooks.server.ts

21 lines
553 B
TypeScript
Raw Normal View History

import { env } from '$env/dynamic/private';
2023-10-18 14:51:52 +00:00
import { Mongo } from '$lib/db/index';
2023-10-06 23:08:13 +00:00
import * as Sentry from '@sentry/node';
2023-10-18 14:51:52 +00:00
import type { Handle, HandleServerError } from '@sveltejs/kit';
2023-10-06 23:08:13 +00:00
Sentry.init({
2023-10-18 14:51:52 +00:00
dsn: env.SENTRY_DSN,
2023-10-06 23:08:13 +00:00
});
interface ServerError extends Error {
code?: string;
}
export const handleError: HandleServerError = ({ error, event }) => {
2023-10-07 02:36:17 +00:00
Sentry.captureException(error, { extra: { event } });
2023-10-06 23:08:13 +00:00
2023-10-07 02:36:17 +00:00
return {
message: 'Uh oh! An unexpected error occurred.',
code: (error as ServerError)?.code ?? '500',
};
2023-10-06 23:08:13 +00:00
};