Spaces:
Paused
Paused
File size: 559 Bytes
04ad412 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /**
* Converts an unknown caught value to an Error. Useful for catch blocks.
*
* Kept local because published embed packages cannot import private `@foxglove/common`.
*
* @param err - The caught value to convert
* @param defaultMessage - Fallback message if `err` is not an Error instance
* @returns The original Error if `err` is an Error, otherwise a new Error with `defaultMessage`
*/
export function toError(err, defaultMessage = "Unknown error") {
if (err instanceof Error) {
return err;
}
return new Error(defaultMessage);
}
|