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
Yes, you should use HTTP status codes. And also preferably return error descriptions in a somewhat standardized JSON format, like Nottingham’s proposal, see apigility Error Reporting:
The payload of an API Problem has the following structure:
- type: a URL to a document describing the error condition (optional, and "about:blank" is assumed if none is provided; should resolve to a human-readable document; Apigility always provides this).
- title: a brief title for the error condition (required; and should be the same for every problem of the same type; Apigility always provides this).
- status: the HTTP status code for the current request (optional; Apigility always provides this).
- detail: error details specific to this request (optional; Apigility requires it for each problem).
- instance: URI identifying the specific instance of this problem (optional; Apigility currently does not provide this).