Errors handling in web services

Revision as of 04:20, 10 April 2012 by jerome mouneyrac (talk | contribs) (Current Moodle web services error handling)

Jump to: navigation, search


Exceptions

Exceptions are caught by the server that generate its own error format. For example in REST:

<?xml version="1.0" encoding="UTF-8"?>
<EXCEPTION class="invalid_parameter_exception">
    <MESSAGE>Invalid parameter value detected</MESSAGE>
    <DEBUGINFO></DEBUGINFO>
</EXCEPTION>

All exceptions contain a translated message + debuginfo.

Error messages

  • 16 functions: only throw exception
  • 2 functions: the web service function catches some exceptions and return a string error message for each faulty element (create notes / send messages)
  • download/upload script return string error message (JSON) + error code. The token script returns just an error message.

Issues

  • clients can not match the function error because message error could be translated
  • web service functions are not consistent: some never return error message (exception is thrown and all transaction are rollbacked), and some bypass DB failure returning an error message (mostly linked to an id).

Suggestion

I think the web service developer still should choose if he wants to return an error message or an exception. The developer should still follow the rule about DB WRITE functions that must rollback when an exception is raised. We usually throw back the exception to the server.

The goal being to let the developer write his own error message, we should add some code error to all exceptions or messages.