Is Restlet returning 415 Unsupported Media Type when it should return 400 Bad Request?

前端 未结 1 1270
梦毁少年i
梦毁少年i 2021-01-05 21:01

I\'m using Restlet 2.1 with jackson to build a json REST api.

When I make a request with the expected content type but a malformed body, I get back a 415 \"Unsuppore

相关标签:
1条回答
  • 2021-01-05 21:17

    415 is correct, as the request is NOT in the right format if it is corrupted in anyway. For example non-parseable JSON or XML. Malformed JSON or XML is NOT JSON or XML by definition, and thus is an unsupported media type, there is no way for Jackson to know that is is supposed to be JSON, it just knows that it isn't JSON that it can parse.

    The offical documentation is really clear about this.

    10.4.16 415 Unsupported Media Type

    The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.

    you said, hey this is JSON, and it isn't so the server says, hey, what I got isn't JSON and not supported by this resource.

    0 讨论(0)
提交回复
热议问题