REST API: how to notify a client that the request has failed when the service already returned 200 and some data?
What I am doing? I am developing a REST Web service that returns data from two sources:
- An CSV file from an HTTP server which changes often and sometimes is huge.
- A local file.
When a client invokes the service, it does this:
- It sends a request to the HTTP server to obtain the CSV file.
- After obtaining the CSV file, it combines the data from both sources.
- Sends the result to the client. The result is an XML document.
Problem Sometimes, after I have already returned some data to the client, the HTTP server fails so I cannot continue sending data to the client. When this happens, I would like to notify the client that there was an error. How should I do this? The service already returned the HTTP code 200 and some data. So I cannot send the client an error 500.
Should I simply write to the output an error message? The client will fail because it the XML-document will not be valid.
The service cannot wait to send the response until the entire file from the HTTP server is read. The reasons is that sometimes the file obtained from the HTTP is very big and does not fit in memory.
Environment: although I do not think this is important, this service is developed in Jersey 1.x.