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

Allow intercepting CORS errors (responses with an error) #133

Closed
wuservices opened this issue Jan 4, 2021 · 1 comment
Closed

Allow intercepting CORS errors (responses with an error) #133

wuservices opened this issue Jan 4, 2021 · 1 comment

Comments

@wuservices
Copy link
Contributor

wuservices commented Jan 4, 2021

I'd like to be able to run auth refresh if there's a CORS error. I've set this up with a library that uses the Salesforce REST API to refresh access tokens, but I've found that the Salesforce API doesn't returns CORS headers once your access token has expired. Therefore, even though the API returns a 401, the browser won't see because the API doesn't returns CORS headers if the access token isn't valid (how silly).

In that scenario, an error like this would be logged to the console:

Access to XMLHttpRequest at 'https://....salesforce.com/services/data/...' from origin '...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

However, there's no specific way to detect this from the callback, so you'd have to intercept all errors.

One way to enable this generically would be to allow using a custom shouldInterceptError method to decide whether to intercept the request. That allows handling this scenario, or any other custom logic.

@Flyrell
Copy link
Owner

Flyrell commented Jan 12, 2021

Thank you for opening the issue and creating a PR (#134). Will publish it as soon as I'm through the other issues with v3.1.0.

@Flyrell Flyrell closed this as completed Jan 12, 2021
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