Skip to main content

Handling exceptions

WebClient or proxy based code dealing with explicit javax.ws.rs.core.Response responses is expected to handle the error HTTP responses itself. Usually, the code will check the response status and if the status indicates the error then some action is taken, for example, an exception can be thrown.

If the custom class such as Book is expected to be returned then org.apache.cxf.jaxrs.client.ServerWebApplicationException will be thrown in case of the HTTP response status being equal or greater than 400.

When working with proxies and in particular with methods which may throw custom checked exceptions, one or more org.apache.cxf.jaxrs.client.ResponseExceptionMapper providers can be registered during the proxy creation. These mappers can convert javax.ws.rs.core.Responses into custom exceptions as required by a given method signature.

Irrespectively of whether the Response or concrete custom class is expected in response to a given call, org.apache.cxf.jaxrs.client.ClientWebApplicationException will be thrown if the invocation has failed on the client side, for example, no connection has been established, no MessageBodyWriter has been found to write the request message or no MessageBodyReader has been found to read the response message, all on the client side.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!