Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should handle empty responses (e.g., CORS errors) #579

Closed
mvdbster opened this issue Jun 6, 2019 · 2 comments
Closed

Should handle empty responses (e.g., CORS errors) #579

mvdbster opened this issue Jun 6, 2019 · 2 comments
Assignees

Comments

@mvdbster
Copy link

mvdbster commented Jun 6, 2019

Some ArcGIS REST requests fail without a response object, for example, when a CORS error occurs.

In this case, arcgis-rest-js seems to throw an error with the string "TypeError: Failed to fetch" instead of the usual error object (see screenshot). This makes it difficult to handle those errors.

Would it be possible to handle these more gracefully?

Screen Shot 2019-06-06 at 11 01 49

@patrickarlt
Copy link
Contributor

As awesome as it might be to detect this this is actually the intended behavior of the spec. See these StackOverflow answers for a little more detail:

basically you cant distinguish between CORS errors and regular network errors because if you COULD then you could maliciously use the failed CORS errors to learn thing about the endpoint you are attacking, like the fact that you can't use CORS or other things.

Chrome and Firefox both add their own "pretty" error messages which are what you see above and in these cases:

Screenshot 2019-07-02 16 59 44
Screenshot 2019-07-02 16 58 51

But our application code only ever sees a TypeError. To try this out paste the following in any DevTools console:

fetch("https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/?f=json&pretty=true")
  .then(r => {
    console.log("Response");
    debugger;
  })
  .catch(e => {
    console.log("Error");
    debugger;
  })

We don't attach a .catch() handler inside request by default right now.

The only potential solution would be to add a .catch() hander to request log some additional messages and then rethrow the error but we can't specially address CORS so the best case message would be something like

ArcGIS REST JS: A Network error occurred. This commonly occurs because:

• You do not have a network connection. Please confirm that you are connected to the internet.
• The URL you requested could not be found. Please confirm that you entered the correct URL.
• The instance of ArcGIS Server or ArcGIS Portal does not have CORS enabled. Either enable CORS or make sure this domain is whitelisted for CORS access

@patrickarlt patrickarlt self-assigned this Jul 3, 2019
patrickarlt added a commit that referenced this issue Jul 12, 2019
* #579 with new utilitiy functions and tests

* restore coverage

* spacing
@patrickarlt
Copy link
Contributor

I'm going to close this. I don't think we need additional documentation on this. It is also going to be tricky to determine what is a network error so we can't really do much about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants