In an ASP.NET MVC 4 REST API application, we have SQL errors which are occuring during the request.

However, since the requests are big, we are streaming the data back to the client, which means we have already returned the 200 OK response and headers.

So midway in the stream, something bad happens. How can we indicate to the downstream client something happened? With XML, we can at least just leave an incomplete file being returned. With CSV though, I cannot come up with a clean way to indicate errors.

What's the best practice for indicating an error occurred in the middle of a REST GET request? Google has somehow failed me on this one

Thank you

  • You mention that with XML you could return an incomplete response, but you don't say if that would be appropriate in your situation. In your use case, is it acceptable for the client to have an incomplete response? Can they still make use of the parts of the response that didn't encounter errors?
    – B. Ithica
    Jan 14, 2021 at 10:45
  • They may be able to make use of the data they have, however realistically they would probably just re-submit the request if a failure occurred. Most of our errors are network errors. If it's a data issue, they could reach out to our support so we can fix it on our end.
    – drew
    Jan 14, 2021 at 14:36

2 Answers 2


Checkout the list of HTTP status code.

Specifically 206 and 416 - The server is delivering only part of the resource (byte serving) due to a range header sent by the client. The range header is used by HTTP clients to enable resuming of interrupted downloads, or split a download into multiple simultaneous streams.

OR just include ERROR ERROR ERROR at the end. :)

  • Thanks for the reply. The problem is that an HTTP 200 has already been returned and the data has started to return to the client as we stream it out of the SQL DB. What happens if it fails halfway through?
    – drew
    Jan 14, 2021 at 14:35

If you are streaming your result it is likely you are using chunked encoding. This just means that there is no Content-Length in the HTTP header, instead there are "frames" (chunks) that are submitted to the client.

There is unfortunately no way to indicate a proper error when you already started streaming the content of the response.

However, chunked encoding must end with a zero-length frame. I.e. it has to be properly terminated. If you don't do that, i.e. just close the connection on the server when you encounter an error, the client should interpret that as an error as well.

Before you think you'll use chunk extensions or the trailer chunk or whatnot, be aware that most http clients don't make those available, and also intermediaries are free to re-chunk the response, so it's not guaranteed you receive the same chunking that the server publishes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.