Skip to content

Commit 968bfee

Browse files
committedJul 21, 2022
fix(isError): use __h3_error__ class property to detect error
soves issue with multiple h3 instances or builds
1 parent 219d24d commit 968bfee

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎src/error.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { MIMES } from './utils'
1414
* @property {Boolean} internal Setting this property to <code>true</code> will mark error as an internal error
1515
*/
1616
export class H3Error extends Error {
17+
static __h3_error__ = true
1718
statusCode: number = 500
1819
fatal: boolean = false
1920
unhandled: boolean = false
@@ -32,7 +33,7 @@ export function createError (input: string | Partial<H3Error>): H3Error {
3233
return new H3Error(input)
3334
}
3435

35-
if (input instanceof H3Error) {
36+
if (isError(input)) {
3637
return input
3738
}
3839

@@ -81,5 +82,5 @@ export function sendError (event: CompatibilityEvent, error: Error | H3Error, de
8182
}
8283

8384
export function isError (input: any): input is H3Error {
84-
return input instanceof H3Error
85+
return input?.constructor?.__h3_error__ === true
8586
}

0 commit comments

Comments
 (0)
Please sign in to comment.