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

    • Icon: Sub-task Sub-task
    • Resolution: Won't Fix
    • Icon: Critical Critical
    • None
    • 2.5
    • JavaScript
    • MOODLE_25_STABLE
    • 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.

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

            timhunt Tim Hunt
            timhunt Tim Hunt
            Votes:
            5 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.