@technobuddha > library > Object > Conversion
Function: toError()
ts
function toError(entity: unknown): Error;Defined in: to-error.ts:17
Convert the entity to an Error object.
Parameters
| Parameter | Type | Description |
|---|---|---|
entity | unknown | The entity to convert, if it is already an error ir will be returned otherwise a new Error object will be created. |
Returns
The entity as an Error object.
Example
typescript
toError(new Error('fail')); // returns the same Error object
toError('fail'); // returns Error: fail
toError(404); // returns Error: 404