mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
* add comments to everything potentially consumer facing * rework smtp --------- Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
18 lines
489 B
TypeScript
18 lines
489 B
TypeScript
/**
|
|
* Converts an unknown thrown value into an Error instance.
|
|
* If `e` is already an Error, wraps it; if a string, uses it as the message;
|
|
* otherwise JSON-serializes it as the error message.
|
|
*
|
|
* @param e - The unknown value to convert
|
|
* @returns An Error instance
|
|
*/
|
|
export const asError = (e: unknown) => {
|
|
if (e instanceof Error) {
|
|
return new Error(e as any)
|
|
}
|
|
if (typeof e === 'string') {
|
|
return new Error(`${e}`)
|
|
}
|
|
return new Error(`${JSON.stringify(e)}`)
|
|
}
|