Files
speckle-server/packages/server/modules/shared/helpers/errorHelper.ts
T
2022-08-24 11:59:30 +03:00

18 lines
518 B
TypeScript

import { BaseError, UnexpectedErrorStructureError } from '@/modules/shared/errors'
/**
* In JS catch clauses can receive not only Errors, but pretty much any other kind of data type, so
* you can use this helper to ensure that whatever is passed in is a real error
*/
export function ensureError(
e: Error | unknown,
fallbackMessage?: string
): Error | BaseError {
if (e instanceof Error) return e
return new UnexpectedErrorStructureError(fallbackMessage, {
info: {
originalError: e
}
})
}