forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getErrorByType.ts
37 lines (35 loc) · 972 Bytes
/
getErrorByType.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { TYPE_UNHANDLED_ERROR, TYPE_UNHANDLED_REJECTION } from '../bus'
import { SupportedErrorEvent } from '../container/Errors'
import { isNodeError } from './nodeStackFrames'
import { getOriginalStackFrames, OriginalStackFrame } from './stack-frame'
export type ReadyRuntimeError = {
id: number
runtime: true
error: Error
frames: OriginalStackFrame[]
}
export async function getErrorByType(
ev: SupportedErrorEvent
): Promise<ReadyRuntimeError> {
const { id, event } = ev
switch (event.type) {
case TYPE_UNHANDLED_ERROR:
case TYPE_UNHANDLED_REJECTION: {
return {
id,
runtime: true,
error: event.reason,
frames: await getOriginalStackFrames(
isNodeError(event.reason),
event.frames
),
}
}
default: {
break
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _: never = event
throw new Error('type system invariant violation')
}