Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-38284 META: Improve core JavaScript processes, etc
  3. MDL-38846

When an AJAX script fails, it should send back a 500 HTTP response code, not 200

    XMLWordPrintable

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Critical
    • Resolution: Won't Fix
    • Affects Version/s: 2.5
    • Fix Version/s: None
    • Component/s: JavaScript
    • Labels:
    • Workaround:
      Hide

      At the top of your ajax script, add

      // Temporary hack until MDL-38846 is fixed. Once that is fixed, these two lines,
      // (of code, plus this comment.) and the line at the bottom can be deleted.
      $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
      @header($protocol . ' 500 Internal Server Error');
      

      and at the end (after all the processing is done, and before you send the response add).

      // Other line to delete once MDL-38846 is fixed
      @header($protocol . ' 200 OK');
       
      That way you will get a 500 status code if an error occurs, and a 200 if no error occurs.
      

      Show
      At the top of your ajax script, add // Temporary hack until MDL-38846 is fixed. Once that is fixed, these two lines, // (of code, plus this comment.) and the line at the bottom can be deleted. $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); @header($protocol . ' 500 Internal Server Error'); and at the end (after all the processing is done, and before you send the response add). // Other line to delete once MDL-38846 is fixed @header($protocol . ' 200 OK');   That way you will get a 500 status code if an error occurs, and a 200 if no error occurs.
    • Affected Branches:
      MOODLE_25_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      We need to tell the JavaScript that it failed! Otherwise errors may be missed.

        Attachments

          Activity

            People

            Assignee:
            timhunt Tim Hunt
            Reporter:
            timhunt Tim Hunt
            Participants:
            Component watchers:
            Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            5 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: