Skip to content

Commit

Permalink
fix(isError): use __h3_error__ class property to detect error
Browse files Browse the repository at this point in the history
soves issue with multiple h3 instances or builds
  • Loading branch information
pi0 committed Jul 21, 2022
1 parent 219d24d commit 968bfee
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { MIMES } from './utils'
* @property {Boolean} internal Setting this property to <code>true</code> will mark error as an internal error
*/
export class H3Error extends Error {
static __h3_error__ = true
statusCode: number = 500
fatal: boolean = false
unhandled: boolean = false
Expand All @@ -32,7 +33,7 @@ export function createError (input: string | Partial<H3Error>): H3Error {
return new H3Error(input)
}

if (input instanceof H3Error) {
if (isError(input)) {
return input
}

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

export function isError (input: any): input is H3Error {
return input instanceof H3Error
return input?.constructor?.__h3_error__ === true
}

0 comments on commit 968bfee

Please sign in to comment.