2

when i have an ajax error response with jquery i have the following log:

jquery.js:8630 OPTIONS http://10.0.1.108:8000/api/v1.0/auth/ net::ERR_CONNECTION_REFUSED
Object {readyState: 0, status: 0, statusText: "error"}

In my object i have a property statusText: 'error', but no properties with 'net::ERR_CONNECTION_REFUSED'.

I tried to log the responseText as see here Get server response with AJAX error? but my object didn't have this property;

Do you know how i can get it in javascript please? Thank.

Community
  • 1
  • 1
user3699170
  • 127
  • 6
  • @Quentin: The cause of the error is not what is being asked – David Hedlund Jun 27 '16 at 15:08
  • What code did you use for the ajax query to get your "object" ("in my object") ? – freedomn-m Jun 27 '16 at 15:10
  • I think its happening because your backend is not ready to accept a cross-origin requests. which framework you are using for backend? – Abhinay Jun 27 '16 at 15:13
  • @Abhinay — What backend? The server is refusing network connections on that port. Detecting that is the point. – Quentin Jun 27 '16 at 15:19
  • @Quentin didn't get your point of shouting though and I said "I think". my intention behind asking about backend is just to provide a backend specific solution. besides I was trying to resolve the error rather than giving him solution on how to log it on client side. – Abhinay Jun 27 '16 at 15:32
  • @Abhinay — What shouting? The question is asking about how to read the error message in JavaScript. It is not asking how to resolve the error. – Quentin Jun 27 '16 at 15:52
  • @Quentin Yes I know but I was trying to help him by bringing his attention to the cause itself which led him think about all these accessing logs etc. and I totally agree with you as well that exposing these information could lead to potential attacks. – Abhinay Jun 27 '16 at 16:13

1 Answers1

4

You can't.

Many errors, including most (if not all) status: 0 errors, are not exposed to JavaScript.

They indicate network or same origin policy errors and exposing the details to JavaScript could leak information. For example, if it was possible to distinguish between "Connection Refused", "Post doesn't speak HTTP" and "No Access-Control-Allow-Origin header", then it would be trivial to write a page that would quietly map out all the webservers on the visitor's corporate network. That information could then be used for phishing attacks.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335