Skip to content

Commit 12a885b

Browse files
authored
Fix error handling when thrown type is not Error (#526)
1 parent 5b60ce0 commit 12a885b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/kit/src/runtime/server/page.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ async function get_response({ request, options, $session, route, status = 200, e
185185
} catch (e) {
186186
// if load fails when we're already rendering the
187187
// error page, there's not a lot we can do
188-
if (error) throw e;
188+
if (error) throw e instanceof Error ? e : new Error(e);
189189

190-
loaded = { error: e, status: 500 };
190+
loaded = { error: e instanceof Error ? e : { message: e.toString() }, status: 500 };
191191
}
192192

193193
if (loaded) {
@@ -268,15 +268,15 @@ async function get_response({ request, options, $session, route, status = 200, e
268268
try {
269269
rendered = options.root.render(props);
270270
} catch (e) {
271-
if (error) throw e;
271+
if (error) throw e instanceof Error ? e : new Error(e);
272272

273273
return await get_response({
274274
request,
275275
options,
276276
$session,
277277
route,
278278
status: 500,
279-
error: e
279+
error: e instanceof Error ? e : { message: e.toString() }
280280
});
281281
}
282282

packages/kit/src/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export type PreloadContext = {
8282

8383
export type LoadResult = {
8484
status?: number;
85-
error?: Error | string;
85+
error?: Error;
8686
redirect?: string;
8787
props?: Record<string, any>;
8888
context?: Record<string, any>;

0 commit comments

Comments
 (0)