2

Here is my current code:

WebTarget resource = client.target(restEndpointURL);
Response response = resource.request().delete();
if (response.getStatusInfo() != Status.OK) {
    String message = String.format("some meaningful error message");
    throw new WebApplicationException(message, response);  
}

I want to throw response status specific exception from here instead of throwing generic WebApplicationException.

vatsal mevada
  • 5,148
  • 7
  • 39
  • 68
  • If the surrounding method declares that it throws WebApplicationException, you can create your own response specific exceptions that extend WebApplicationException. – Luciano van der Veekens Jun 01 '17 at 09:13
  • I think there is no need of creating my own exception. Jersey-2 provides status code specific exceptions. I can add a switch case in my code where based on status code I'll throw the specific exception. However, I am curious whether Jersey-2 provides some utility method to achieve the same. – vatsal mevada Jun 01 '17 at 10:06

0 Answers0