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

Web service exception should return errorcode (from moodle exception)

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.3
    • 2.3
    • Web Services
    • None
    • MOODLE_23_STABLE
    • MOODLE_23_STABLE
    • 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.

    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

              jerome Jérôme Mouneyrac
              jerome Jérôme Mouneyrac
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Adrian Greeve Adrian Greeve
              Juan Leyva, David Woloszyn, Huong Nguyen, Jake Dallimore, Michael Hawkins, Stevani Andolo
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                25/Jun/12