What should a JSON service return on failure / error

后端 未结 11 1144
温柔的废话
温柔的废话 2020-12-02 05:32

I\'m writing a JSON service in C# (.ashx file). On a successful request to the service I return some JSON data. If the request fails, either because an exception was thrown

11条回答
  •  我在风中等你
    2020-12-02 06:38

    Using HTTP status codes would be a RESTful way to do it, but that would suggest you make the rest of the interface RESTful using resource URIs and so on.

    In truth, define the interface as you like (return an error object, for example, detailing the property with the error, and a chunk of HTML that explains it, etc), but once you've decided on something that works in a prototype, be ruthlessly consistent.

提交回复
热议问题