extractErrorMessage
Convert an error to a readable message.
Available since v1.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
error | unknown | an error |
stringify | string | true | stringifies the error if no extractable message is found |
Returns
Section titled “Returns”string — a readable message or a stringified error if stringify is true, otherwise undefined
Examples
Section titled “Examples”Extract message from Error object
Section titled “Extract message from Error object”Returns the stringified Error, including the class prefix.
Handle string errors
Section titled “Handle string errors”Returns the string directly when the error is a plain string.
Stringify unknown errors
Section titled “Stringify unknown errors”When stringify is true, falls back to JSON.stringify for unrecognized errors.
