Trace:
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
jvx:communication:rest_exceptionhandling [2019/07/09 09:19] admin created |
jvx:communication:rest_exceptionhandling [2020/06/08 16:02] (current) cduncan |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ~~NOTRANS~~ | ~~NOTRANS~~ | ||
| - | ~~Title: Publish/Push messages~~ | + | ~~Title: REST Exception Handling~~ |
| - | Our standard [[jvx:common:util:rest|REST services]] come with standard exception handling. This means that all server-side exceptions send the http status code 400 (Bad Request) to the client. The implementation already checks some exception types and returns custom http status codes: | + | Our standard [[jvx:common:util:rest|REST services]] come with standard exception handling. This means that all server-side exceptions will send the http status code 400 (Bad Request) to the client. The implementation already checks some exception types and returns custom http status codes: |
| ^ Exception ^ http status ^ | ^ Exception ^ http status ^ | ||
| - | | UnknownObjectException | 404 (not found) | | + | | UnknownObjectException | 404 (Not found) | |
| - | | SecurityException | 403 (forbidden) | | + | | SecurityException | 403 (Forbidden) | |
| - | | InvalidPasswordException | 401 (unauthorized) | | + | | InvalidPasswordException | 401 (Unauthorized) | |
| - | If you want custom status codes, it's possible to throw **RestServiceException**. This Exception class supports custom status codes and error messages. | + | If you want custom status codes, it's possible to throw **RestServiceException**. This exception class supports custom status codes and error details. |
| + | <file java> | ||
| + | if (!isBookingAvailable()) | ||
| + | { | ||
| + | IBean details = new Bean(); | ||
| + | details.put("id", errorId); | ||
| + | details.put("message", "The booking feature isn't yet implemented!"); | ||
| + | |||
| + | throw new RestServiceException(501, details); | ||
| + | } | ||
| + | |||
| + | ... | ||
| + | </file> | ||
