0

This is a very similar question, but mine is more specific.

If I type in an invalid resource path, like /foobar, it returns a 404. I'd like this to return a 400. 400 is "bad request". I feel like this is more informative to the client. How I can configure Jersey 1.x to return this instead?

Community
  • 1
  • 1
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
  • Why do you have that feeling? What about it makes it a bad request as defined in the HTTP spec? – Sotirios Delimanolis Feb 14 '14 at 00:57
  • @SotiriosDelimanolis in the sense that the client has [definitely made a mistake and should not try again](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1). I feel a 404 is more appropriate for a path like '/users/1234' where you're looking for a user with that key but he's not in the system. Perhaps that user key will be there tomorrow. But the wrong path is definitely wrong. – Daniel Kaplan Feb 14 '14 at 01:09
  • 2
    I'll tell you right now I have no idea how to do this with Jersey, but I doubt very much it is possible out of the box. However, I'd like to try and convince you that 404 is the appropriate code. The HTTP spec says `The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.` about a 404. The resource `/foobar` would not exist. There's nothing bad about the request. The server understands it, but there is no corresponding resource for it. – Sotirios Delimanolis Feb 14 '14 at 01:16
  • 2
    A Bad Request means `The request could not be understood by the server due to malformed syntax.` That doesn't seem to be the case in the example you've given. It doesn't seem appropriate. – Sotirios Delimanolis Feb 14 '14 at 01:16
  • @SotiriosDelimanolis hm I think I understand. The syntax is fine so it shouldn't be a 400. Technically this question is unanswered, so I suppose I'll leave it open, but I no longer want to change the default. – Daniel Kaplan Feb 14 '14 at 01:17

0 Answers0