1

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:

  1. the service always answers with the http status code 200 (ok) even if there was an error

  2. 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."}".

  3. the error is packed in json but the answer is xml

  4. 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

Post's attachments

indicia.diff 2.29 kb, 2 downloads since 2012-11-30 

You don't have the permssions to download the attachments of this post.

2

Re: Error Handling of the Indicia data service

Thanks Daniel, that makes sense but as you say we need to make sure this does not impact existing code, I'll review that patch and see what happens on my local setup.

John van Breda
Biodiverse IT

3

Re: Error Handling of the Indicia data service

Hi Daniel
After trying this out, I've found that there are indeed some dependencies which break in the client-side code after applying this patch. I'm thinking of making this new "correct" behaviour an option you can turn on in the warehouse as it will be difficult
for us to synchronise a change out to all the client sites. Does this sound fair?
Thanks
John

John van Breda
Biodiverse IT

4

Re: Error Handling of the Indicia data service

Hi John,

this sound like a reasonable solution. But I've notice that my patch is not correct: it returns the response in xml even if you make a submission in json...

I hope I can create a new patch next week, which includes the config option an correct behavior depending on the requested format. Any suggestion for the name of the option? Default old behaviour?
And can you tell me a where I can see how config options are handled in the source?

Regards

Daniel

5

Re: Error Handling of the Indicia data service

Hi John,

here is a second try for the patch. There is now a configuration parameter for turning the new behaviour on. Feel free to rename it to what you like. Is the content type a problem to your code? If, then I will make it also be set depending on the configuration.

Greetings

Daniel

Post's attachments

indicia.diff 3.42 kb, 1 downloads since 2012-12-16 

You don't have the permssions to download the attachments of this post.

6

Re: Error Handling of the Indicia data service

Hi Daniel
I'd already done something similar but not finished it when I saw your patch - thanks though. I've now committed something which I hope will fix the issues you are having in r5073. Some notes on things which I needed to do for backwards compatibility:
1) Default input and output mode for web services is now JSON (which is what we use elsewhere for our client). If you want to use XML then you must specify mode=xml.
2) I didn't change the error message returned for an authorisation failure since that is output by our client to the user.
3) Because the http status codes break our client, I've updated the client, but for backwards compatibility you must turn on the indicia.http_status_responses configuration option (similar to your idea - see application/config/config.php.example for an example - just copy the variable to your application/config/config.php).

The content type problem does not seem to be an issue though.

Cheers
John

John van Breda
Biodiverse IT

7

Re: Error Handling of the Indicia data service

Hi John,

the option has to be in application/config/indicia.php or the "indicia." prefix has to be removed in the check.

Else it works.

Thanks

Daniel

8

Re: Error Handling of the Indicia data service

Thanks Daniel, I've fixed this in trunk.
Best wishes
John

John van Breda
Biodiverse IT