JKS
JKS

Reputation: 3770

How can I catch Access-Control errors?

I'm working with an API that sometimes doesn't set the right Access-Control headers for CORS requests.

How can I inform the user that something went wrong when an Access-Control error occurs? I don't even need to know what error occurred, just that the XHR request failed.

Wrapping the request in a try/catch block doesn't seem to work in WebKit browsers.

Upvotes: 0

Views: 360

Answers (2)

maxl0rd
maxl0rd

Reputation: 1446

Using jQuery? You can attach global error handlers with $.ajaxError().

Upvotes: 0

J. K.
J. K.

Reputation: 8368

I would suggest attaching an onerror handler to the XMLHttpRequest instance.

Upvotes: 1

Related Questions