Topic: Error Handling of the Indicia data service
Hi,
I've experienced some non intuitive behaviour of the indicia data service when it comes to an error:
the service always answers with the http status code 200 (ok) even if there was an error
if the authorization fails the service answers with the message "{"error":"An error occurred, possibly as a result of taking too long to fill in a data entry form, using the browser's Back button and resubmitting a form twice or because the form is not configured correctly."}".
the error is packed in json but the answer is xml
the contend type of an error is text/html which is not fitting to the delivered contend
The reason for 2 is an translation entry in the file application/i18n/en_GB/general_errors.php added in r4185.
The reason for 3 is a call of get_input_mode() in line 186 of the file application/controller/service_base.php it should be changed to get_output_mode()
The attached patch sets the http status code in an case of an error to 500 and if authorization fails to 403. It also sets the correct content-type. This solves my issues, but maybe it breaks other ones error handling which relies on always 200?
I think the error handling should be re factored in general. Throwing an exception with a code and a message -> setting the http code depending on the code (and configuration to be backwards compatible?), -> prepare a response data structure -> render it depending on the output type.
If I find some time for this, I would like to see if I can do that. But if someone else wants...
Regards
Daniel
Regards
Daniel