0

I am handling the error in a if block in the method where I receive the response from the server. I put the server down in order to test the service unavailable scenario

_onResponse: function (err, res) {
   if (err){
 }

on doing alert("error " + err); I receive

Error: Request has been terminated
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
    at Request.crossDomainError (http://localhost:9000/index.js:33875:14)
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:9000/index.js:33945:20)

I want to read the value of Error:

I tried doing err.message but then I receive the entire body of the error. I tried with err.name I just get the text 'Error'

How do I get the content Request has been terminated in a javascript variable?

underdog
  • 4,447
  • 9
  • 44
  • 89
  • May this link will help you:- http://stackoverflow.com/questions/1637019/how-to-get-the-jquery-ajax-error-response-text – Ravi Hirani Mar 10 '16 at 06:04

1 Answers1

0

From the response all I can say is this is not the error your server is sending. It is raised by the engine while doing XHR to a domain for which CORS is disabled. To catch this error, wrap the XHR code in index.js around line 33945 in a try{} catch(e){} block. Inside catch block you get hold of the error using the e variable.

Your block will handle error only when you get a response from the target server.

Ravi Tiwari
  • 946
  • 8
  • 17