Function: statusOfError()
statusOfError(
error):number
Find the HTTP status of an error, read from its statusCode or status: the first client error (4xx) found on the error or along its cause chain, else the error's own status when it is between 400 and 599, else 500. A validation failure, wrapped in an exception whose cause is the 400 validation error, thus gives 400.
Parameters
error
unknown
The error, any value.
Returns
number
The HTTP status, from 400 to 599.
Example
typescript
import {statusOfError} from 'lakutata/adapter/express'
class NotFound extends Error {
public readonly statusCode: number = 404
}
console.log(statusOfError(new NotFound('No such order'))) //404
console.log(statusOfError(new Error('Failed', {cause: new NotFound('No such order')}))) //404
console.log(statusOfError(new Error('Boom'))) //500