Question

i wrote a pretty standard multipart file upload restful service. When I was using curl to test it I kept getting 400 bad request. It turned out to be a variety of reasons but I always got this same 400 bad request. For instance, my temp directory of my application server was non existent. I would expect some lower level exception to be thrown in the logs but I couldn't see anything. I am not too familiar with Jersey and looking for any advice on how I could handle this to still return 400 / bad request but somehow log some more information. Any ideas? I am using jersey 1.x

Was it helpful?

Solution

If the error occurs in your own method you can use a Response as return type for your methods. Then you can specify both the status code and the returned message body.

throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity("<your message here>").build());

In case the error occurs in some other framework, the exception should be logged to stderr. Depending on what Webserver you use you might be able to configure it in order to send exceptions as Response bodies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top