Skip to content

Commit

Permalink
adds javalin exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
nimonian committed Oct 6, 2024
1 parent 34d57c7 commit 7c80a3b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/javalin/sending-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ if (limit < 0 || offset < 0) {
}
```

Here are some useful built-in exceptions:

| Name | Description |
| :---------------------------: | ------------------------------------------------------------------------------------------ |
| `BadRequestResponse` | Returns a 400 Bad Request response with the default title Bad request. |
| `UnauthorizedResponse` | Returns a 401 Unauthorized response with the default title Unauthorized. |
| `ForbiddenResponse` | Returns a 403 Forbidden response with the default title Forbidden. |
| `NotFoundResponse` | Returns a 404 Not Found response with the default title Not found. |
| `InternalServerErrorResponse` | Returns a 500 Internal Server Error response with the default title Internal server error. |

## Fallback exception handling

If an exception is thrown which Javalin does not know how to handle, it will be
Expand All @@ -57,3 +67,39 @@ app.exception(Exception.class, (e, ctx) -> {
ctx.result("An unkown error occurred.");
});
```

<!-- RedirectResponse
Returns a 302 Found response with the default title Redirected.
BadRequestResponse
Returns a 400 Bad Request response with the default title Bad request.
UnauthorizedResponse
Returns a 401 Unauthorized response with the default title Unauthorized.
ForbiddenResponse
Returns a 403 Forbidden response with the default title Forbidden.
NotFoundResponse
Returns a 404 Not Found response with the default title Not found.
MethodNotAllowedResponse
Returns a 405 Method Not Allowed response with the default title Method not allowed.
ConflictResponse
Returns a 409 Conflict response with the default title Conflict.
GoneResponse
Returns a 410 Gone response with the default title Gone.
InternalServerErrorResponse
Returns a 500 Internal Server Error response with the default title Internal server error.
BadGatewayResponse
Returns a 502 Bad Gateway response with the default title Bad gateway.
ServiceUnavailableResponse
Returns a 503 Service Unavailable response with the default title Service unavailable.
GatewayTimeoutResponse
Returns a 504 Gateway Timeout response with the default title Gateway timeout. -->

0 comments on commit 7c80a3b

Please sign in to comment.