Reputation: 8627
I'm trying to implement a simple interceptor that allows me to display a message along the lines of "cannot contact the server" in my Angular app. However as the API is on a different host I'm dealing with CORS pre-flight OPTIONS
requests.
I've found that if the API is unavailable Chrome dev tools shows a 503
on the OPTIONS
request but Angular's $http
interceptor catches a 404
response to the subsequent GET
request. I believe this is because the OPTIONS
response did not contain the required CORS headers so the GET
is actually never performed.
Is is possible to intercept the OPTIONS
response? If all I see is a 404
I can't distinguish "server down" from "no such resource".
Upvotes: 8
Views: 7132
Reputation: 4623
You can't intercept this request by design - the browser is "checking up" on you, making sure YOU should be allowed to make the request.
We've used three solutions to work around this:
Upvotes: 3