Skip to content

Commit 8213421

Browse files
danielroepi0
andauthoredAug 10, 2022
fix(createError): preserve original error stack (#161)
Co-authored-by: Pooya Parsa <pooya@pi0.io>
1 parent ccc9c7e commit 8213421

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎src/error.ts

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ export function createError (input: string | Partial<H3Error>): H3Error {
3939

4040
const err = new H3Error(input.message ?? input.statusMessage, input.cause ? { cause: input.cause } : undefined)
4141

42+
if ('stack' in input) {
43+
try {
44+
Object.defineProperty(err, 'stack', { get () { return input.stack } })
45+
} catch {
46+
try { err.stack = input.stack } catch {}
47+
}
48+
}
49+
4250
if (input.statusCode) { err.statusCode = input.statusCode }
4351
if (input.statusMessage) { err.statusMessage = input.statusMessage }
4452
if (input.data) { err.data = input.data }

0 commit comments

Comments
 (0)
Please sign in to comment.