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

Web service exception should return errorcode (from moodle exception)

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.3
    • Component/s: Web Services
    • Labels:
      None
    • Testing Instructions:
      Hide

      Dome clients: https://github.com/moodlehq/sample-ws-clients

      Run the REST demo client with json then xml. The second time you'll run it on core_user_create_users it should throw an exception as the user are already created. Check that both json/xml return errorcode.

      Run the XML-RPC and SOAP demo client, check that errorcode are also returned.

      Show
      Dome clients: https://github.com/moodlehq/sample-ws-clients Run the REST demo client with json then xml. The second time you'll run it on core_user_create_users it should throw an exception as the user are already created. Check that both json/xml return errorcode. Run the XML-RPC and SOAP demo client, check that errorcode are also returned.
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE
    • Pull Master Branch:

      Description

      Add error code in REST/SOAP/...

      example REST-XML:

      <?xml version="1.0" encoding="UTF-8"?>
      <EXCEPTION class="moodle_exception">
          <ERRORCODE>missingcourse</ERRORCODE>
          <MESSAGE>This is a not translated message</MESSAGE>
          <DEBUGINFO>This is a not translated message with more detailled info</DEBUGINFO>
      </EXCEPTION>

      example SOAP change in webservice/soap/locallib.php:

      public function fault($fault = null, $code = "Receiver")
          {
              //intercept any exceptions with debug info and transform it in Moodle exception
              if ($fault instanceof Exception) {
                  //add the debuginfo to the exception message if debuginfo must be returned
                  if (debugging() and isset($fault->debuginfo)) {
                      $fault = new SoapFault($fault->errorcode, $fault->getMessage() . ' | DEBUG INFO: ' . $fault->debuginfo); //HERE IS THE CHANGE $fault->errorcode PS: NOT TESTED ;)
                  }
              }
       
              return parent::fault($fault, $code);
          }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jerome Jérôme Mouneyrac
                Reporter:
                jerome Jérôme Mouneyrac
                Peer reviewer:
                Eloy Lafuente (stronk7)
                Integrator:
                Eloy Lafuente (stronk7)
                Tester:
                Adrian Greeve
                Participants:
                Component watchers:
                Juan Leyva, Jake Dallimore, Jun Pataleta
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  25/Jun/12