You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
620 B
25 lines
620 B
export type EndpointHandler = (req: any, res: any) => Promise<void>; |
|
|
|
export interface EndpointError { |
|
internalMessage: String; |
|
httpStatus: Number; |
|
} |
|
|
|
export function isEndpointError(obj: any): obj is EndpointError { |
|
return obj.internalMessage !== undefined && |
|
obj.httpStatus !== undefined; |
|
} |
|
|
|
export const catchUnhandledErrors = (_e: any) => { |
|
if (isEndpointError(_e)) { |
|
// Rethrow |
|
throw _e; |
|
} |
|
|
|
// This is an unhandled error, make an internal server error out of it. |
|
const e: EndpointError = { |
|
internalMessage: _e, |
|
httpStatus: 500 |
|
} |
|
throw e; |
|
} |