toError
Coerces an unknown thrown value into a proper Error instance.
Handles the common cases where libraries throw non-Error values
(e.g. plain API response bodies, arrays, Maps) that would otherwise
serialize as [object Object] in error messages.
Usage
toError(thrown: unknown)
Coerces an unknown thrown value into a proper Error instance.
Handles the common cases where libraries throw non-Error values
(e.g. plain API response bodies, arrays, Maps) that would otherwise
serialize as [object Object] in error messages.
Parameters
thrownunknownrequired
the caught value to normalize.
Returns
An Error with a meaningful .message. If thrown is already an Error, it is returned as-is. The original value is preserved as .cause for debugging.