2021-10-25 13:05:21 +00:00
|
|
|
export function getErrorFromUnknown(cause: unknown): Error & { statusCode?: number; code?: unknown } {
|
2021-10-20 15:42:40 +00:00
|
|
|
if (cause instanceof Error) {
|
|
|
|
return cause;
|
|
|
|
}
|
|
|
|
if (typeof cause === "string") {
|
|
|
|
// @ts-expect-error https://github.com/tc39/proposal-error-cause
|
|
|
|
return new Error(cause, { cause });
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Error(`Unhandled error of type '${typeof cause}''`);
|
|
|
|
}
|