1

I setup a Global AJAX error handling function, this way , but I don't see how to test it ? anyway in a jsFiddle

  $(function () {
      var statusErrorMap = {
        '400' : "Server understood the request, but request content was invalid.",
        '401' : "Unauthorized access.",
        '403' : "Forbidden resource can't be accessed.",
        '500' : "Internal server error.",
        '503' : "Service unavailable."
      };
      //setup ajax error handling
      $.ajaxSetup({
          error: function (x, status, error) {
              if  (x.status in statusErrorMap) {
                if (x.status == "503") {
                    alert("Sorry, your session has expired. Please login again to continue");
                    window.location.href ="/users/sign_in";
                } else {
                  alert("("+ x.status +") error occurred: " + statusErrorMap[x.status.toString()]);
                }
              }
              else {
                alert("An error occurred: " + status + "nError: " + error);
              }              
          }
      });
  });

1 Answers1

0

You have to use fiddler (Proxy tool) to intercept the server request and test you error handling code. For that you have to set a breakpoint for your service call in fiddler and follow below process.

  1. Rules > Automatic Breakpoints > After Responses
  2. In the quickexec box (the black box at the bottom) type "bpafter yourpage.svc". Now Fiddler will stop at a breakpoint before all requests to any URL that contains "yourpage.svc". Type "bpafter" with no parameters to clear the breakpoint.
  3. Programmatically tamper with the response using FiddlerScript. The best documentation for FiddlerScript is on the official site: http://www.fiddler2.com/Fiddler/dev/

You can get additioanl details in below stackoverflow.

How do I use Fiddler to modify the status code in an HTTP response?

Community
  • 1
  • 1
Ravi Dasari
  • 453
  • 1
  • 4
  • 10