Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-67176

Web services should not use status 200 for exceptions

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.7.2
    • Fix Version/s: None
    • Component/s: Web Services
    • Labels:
      None
    • Affected Branches:
      MOODLE_37_STABLE

      Description

      When Moodle's built-in web services return an exception, this is often or always returned with an HTTP status 200. For example, if we submit a request to mod_assign_save_grade with an invalid parameter, we receive the response:

      Exception: invalid_parameter_exception
      Error Code: invalidparameter
      Message: Invalid parameter value detected
      

       
      This is returned with an HTTP status code 200 (OK). The 200 code is supposed to indicate that a request succeeded. It is not the appropriate code to use if we passed in bad parameters and got back an exception. A more appropriate code for this example would be 400 (Bad Request).

      Use of the correct HTTP status codes would allow our client-side code to more elegantly handle  responses from the server without having to parse every single response for exceptions.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            kevinfoley Kevin Foley
            Participants:
            Component watchers:
            Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: