Normalizes unknown thrown input into an Error instance.
Returns the input unchanged when it is already an Error. Wraps strings in a
new Error (empty strings use the fallback message). For error-like objects,
copies message and preserves name/stack when present.
Parameters
error: unknown
Unknown thrown value from a catch block or Promise rejection.
Returns Error
The same Error when already an instance; a new Error for strings and error-like objects (copying name/stack when present); a serialized fallback for other values.
Example
ensureError(newError("boom")); // same Error instance ensureError("boom"); // Error("boom") ensureError(""); // Error("An unknown error occurred.") ensureError({ message:"boom", name:"CustomError" }); // Error with copied name ensureError(404); // Error('Error: 404')
Normalizes unknown thrown input into an
Errorinstance.Returns the input unchanged when it is already an
Error. Wraps strings in a newError(empty strings use the fallback message). For error-like objects, copiesmessageand preservesname/stackwhen present.