Kauri Documentation
 PreviousHomeNext 
15.2 API and ServicesBook Index16.1.2 Case 2: throw an exception

16 Error handling

16.1 Different ways of handling error situations

When a resource class encounters an error situation (bad client request, error from backend, ...), there are different ways to deal with it:

  1. Produce the complete error response: set the appropriate status code and a response body.

  2. Throw an exception. Catching the exception and creating the appropriate response becomes the responsibility of a downstream filter.

  3. Set only the response status, but not the response body. The Restlet API allows the status to include a custom description and a Throwable object. Creating the response body becomes the responsibility of a downstream filter.

16.1.1 Case 1: resource class produces complete error response

This is interesting if you want to provide very specific error responses. This will especially be useful in Webservice (REST-API) style resources, and less for user-facing web applications.

If a resource class formats all errors it might produce itself, it is completely self-contained without relying on any downstream filters to do further work for them.

 PreviousHomeNext 
15.2 API and Services16.1.2 Case 2: throw an exception