Skip to content

Commit 457ea90

Browse files
committed
handle uncaught exceptions properly
1 parent f934239 commit 457ea90

File tree

1 file changed

+5
-5
lines changed
  • packages/sveltekit/src/server

1 file changed

+5
-5
lines changed

packages/sveltekit/src/server/load.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function isHttpError(err: unknown): err is HttpError {
66
return typeof err === 'object' && err !== null && 'status' in err && 'body' in err;
77
}
88

9-
function captureAndThrowError(e: unknown): void {
9+
function sendErrorToSentry(e: unknown): unknown {
1010
// In case we have a primitive, wrap it in the equivalent wrapper class (string -> String, etc.) so that we can
1111
// store a seen flag on it.
1212
const objectifiedErr = objectify(e);
@@ -15,7 +15,7 @@ function captureAndThrowError(e: unknown): void {
1515
// If we detect a thrown error that is an instance of HttpError, we don't want to capture 4xx errors as they
1616
// could be noisy.
1717
if (isHttpError(objectifiedErr) && objectifiedErr.status < 500 && objectifiedErr.status >= 400) {
18-
throw objectifiedErr;
18+
return objectifiedErr;
1919
}
2020

2121
captureException(objectifiedErr, scope => {
@@ -33,7 +33,7 @@ function captureAndThrowError(e: unknown): void {
3333
return scope;
3434
});
3535

36-
throw objectifiedErr;
36+
return objectifiedErr;
3737
}
3838

3939
/**
@@ -49,12 +49,12 @@ export function wrapLoadWithSentry(origLoad: ServerLoad): ServerLoad {
4949
try {
5050
maybePromiseResult = wrappingTarget.apply(thisArg, args);
5151
} catch (e) {
52-
captureAndThrowError(e);
52+
throw sendErrorToSentry(e);
5353
}
5454

5555
if (isThenable(maybePromiseResult)) {
5656
Promise.resolve(maybePromiseResult).then(null, e => {
57-
captureAndThrowError(e);
57+
sendErrorToSentry(e);
5858
});
5959
}
6060

0 commit comments

Comments
 (0)