rosdiff / api /static /foxglove-embed /toError.js
Chandra Kiran
Harden simulation runs: official Foxglove embed, WebM video, CI image build
04ad412 unverified
Raw History Blame Contribute Delete
559 Bytes
/**
* 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);
}