rest.js icon indicating copy to clipboard operation
rest.js copied to clipboard

[BUG]: HttpError: Failed to fetch (CORS policy)

Open mchestnut opened this issue 1 year ago • 2 comments

What happened?

We are seeing sporadic POST requests using octokit/rest.js failing. The requests come back with the error HttpError: Failed to fetch and Access to fetch at 'https://api.github.com/repos/ChapmanAutoGroup/sites.retail/git/trees' from origin [our site] has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

We're calling the git.createTree and git.createBlob methods. We have seen it fail on either one at different times.

We've also noticed that attempting the same exact request using the same headers and payload will eventually result in a success, although the number of retries can vary from 1 to over a dozen.

The library is being using in a Vue app. We've seen the error running both locally and on a production server.

Any ideas what is causing the CORS issue?

Versions

node: 18.17.1 @octokit/rest: 20.0.2

Relevant log output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

mchestnut avatar Jan 11 '24 21:01 mchestnut

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

github-actions[bot] avatar Jan 11 '24 21:01 github-actions[bot]

This seems more like a GitHub infrastructure issue than an issue with Octokit itself

wolfy1339 avatar Apr 11 '24 01:04 wolfy1339

experiencing the same - can someone have a look at this?

cscheffauer avatar Jul 08 '24 17:07 cscheffauer

Please raise this issue with GitHub.

CORS issues are server-side, not client-side.

There is nothing we can do. It's GitHub that has not set the required header.

wolfy1339 avatar Jul 08 '24 17:07 wolfy1339