getErrorResponse()function
getErrorResponse(reason: unknown, debug = false): Response
| Param | Type | |
|---|---|---|
reason | unknown | The error value to convert to a Response. required |
debug | unknown | If true include the error message in the response (for debugging), or false to return generic error codes (for security). Defaults to false. Defaults to false |
| Return | |
|---|---|
Response | A Response with a status code and (optionally) body derived from the error. |
Get an HTTP Response for an unknown error value.
Returns the correct Response based on the type of error thrown:
- If
reasonis aResponseinstance, return it directly. - If
reasonis a string, return a 422 response with the string message, e.g."Invalid input" - If
reasonis anRequestErrorinstance, return a response with the error's message and code (but only ifdebugis true so we don't leak error details to the client). - If
reasonis anErrorinstance, return a 500 response with the error's message (but only ifdebugis true so we don't leak error details to the client). - Anything else returns a 500 response.
Examples
getErrorResponse("Invalid input") // 422 Response