Skip to content

Commit 54ba88a

Browse files
fix: Dumber fix for error assertions
1 parent 8e27c71 commit 54ba88a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

packages/kit/src/exports/index.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,14 @@ export function error(status, body) {
8585
* @return {e is (HttpError & { status: T extends undefined ? never : T })}
8686
*/
8787
export function isHttpError(e, status) {
88-
if (!(e instanceof HttpError)) return false;
89-
return !status || e.status === status;
88+
return (
89+
typeof e === 'object' &&
90+
e !== null &&
91+
Object.hasOwn(e, '_tag') &&
92+
Object.hasOwn(e, 'status') &&
93+
/** @type {{ _tag: string; }} */ (e)._tag === 'SvelteKitHttpError' &&
94+
(!status || /** @type {{ status: number }} */ (e).status === status)
95+
);
9096
}
9197

9298
/**
@@ -124,7 +130,12 @@ export function redirect(status, location) {
124130
* @return {e is Redirect}
125131
*/
126132
export function isRedirect(e) {
127-
return e instanceof Redirect;
133+
return (
134+
typeof e === 'object' &&
135+
e !== null &&
136+
Object.hasOwn(e, '_tag') &&
137+
/** @type {{ _tag: string }} */ (e)._tag === 'SvelteKitRedirect'
138+
);
128139
}
129140

130141
/**
@@ -213,7 +224,12 @@ export function fail(status, data) {
213224
* @return {e is import('./public.js').ActionFailure}
214225
*/
215226
export function isActionFailure(e) {
216-
return e instanceof ActionFailure;
227+
return (
228+
typeof e === 'object' &&
229+
e !== null &&
230+
Object.hasOwn(e, '_tag') &&
231+
/** @type {{ _tag: string }} */ (e)._tag === 'SvelteKitActionFailure'
232+
);
217233
}
218234

219235
/**

packages/kit/src/runtime/control.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export class HttpError {
2+
/** @private */
3+
_tag = 'SvelteKitHttpError';
4+
25
/**
36
* @param {number} status
47
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
@@ -20,6 +23,9 @@ export class HttpError {
2023
}
2124

2225
export class Redirect {
26+
/** @private */
27+
_tag = 'SvelteKitRedirect';
28+
2329
/**
2430
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
2531
* @param {string} location
@@ -52,6 +58,9 @@ export class SvelteKitError extends Error {
5258
* @template {Record<string, unknown> | undefined} [T=undefined]
5359
*/
5460
export class ActionFailure {
61+
/** @private */
62+
_tag = 'SvelteKitActionFailure';
63+
5564
/**
5665
* @param {number} status
5766
* @param {T} data

0 commit comments

Comments
 (0)