-
Notifications
You must be signed in to change notification settings - Fork 4
HTTP Status Code Responses
Chris Phillips edited this page Jun 28, 2024
·
3 revisions
There will be times where you want your API to return non-default HTTP status codes (e.g. 404). Relaxation gives you a simple way to make this happen while still allowing the code in your services and controllers to be reusable. If you throw certain ErrorCode(s), you will get specific HTTP status codes as the response.
e.g.
Throw (,
errorCode = "NotAuthorized",
message = "Current user is not allowed to delete widgets"
type = "acme.NotAllowed"
);
// returns '403 Forbidden'
Below are the ErrorCode(s) and the HTTP status codes they will return.
ErrorCode | Status Code | Status Text |
---|---|---|
ClientError | 400 | Bad Request |
NotAuthorized | 403 | Forbidden |
ResourceNotFound | 404 | Not Found |
VerbNotFound | 405 | Method Not Allowed |
ConflictError | 409 | Conflict |
TooManyRequests | 429 | Too Many Requests |
ServerError | 500 | Internal Server Error |