question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storage API doesn't throw error even if the CORS error

See original GitHub issue

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

Storage

Amplify Categories

storage

Environment information

Chrome

Describe the bug

Hi

We found a point for improvement in Storage API. Storage API can’t catch error even if CORS error occurs, the Promise is resolved. I think it is better Storage API throw error.

StorageAPI-sample-code

async function put_s3() {
  // Specify a bucket that does not exist
  await Storage.put("test.txt", "Hello", { bucket: "XXXXX" }).then(
    (result) => {
      console.log("result!!!!");
      console.log(result)
    }
  ).catch(
    (error) => {
      console.log("error!!!!");
      console.log(error)
    }
  )
}

Browsers console log(Chrome)

Access to XMLHttpRequest at 'https://XXXXX.s3.ap-northeast-1.amazonaws.com/public/test.txt?x-id=PutObject' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
index.js:1 [ERROR] 39:07.605 axios-http-handler - Network Error
...
App.js:48 result!!!!
App.js:49 {key: 'test.txt'}

I think this behavior is a little strange. I checked the behavior of axios, they throwed error.

axios-sample-code

  axios.post('/items')
    .then((response) => {
      console.log(response);
    })
    .catch((error) => {
      console.log("error!!!");
      console.log(error);
    });

Browsers console log

localhost/:1 Access to XMLHttpRequest at 'https://XXXXX/items' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
App.js:40 error!!!
App.js:41 Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:99)
xhr.js:187 POST https://XXXXX/items net::ERR_FAILED 200

I checked Similar this issues https://github.com/aws-amplify/amplify-js/issues/3419

But this issues seems to be fixed.

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jamesaucodecommented, Feb 10, 2022

Thanks for reporting. Looking into this issue now

1reaction
deepak-agarwalcommented, Feb 1, 2022

Facing the same issue.

Even if you go offline in between an upload, the Storage.put promise is resolved. Should throw an error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Ways to Fix the CORS Error — and How the Access-Control ...
Fix one: install the Allow-Control-Allow-Origin plugin. The quickest fix you can make is to install the moesif CORS extension .
Read more >
Fixing Common Problems with CORS and JavaScript
Tutorial: This post walks through troubleshooting and fixing common problems associated with calling REST APIs from JavaScript.
Read more >
Troubleshoot CORS errors from API Gateway - Amazon AWS
Cross-Origin Resource Sharing (CORS) errors occur when a server doesn't return the HTTP headers required by the CORS standard.
Read more >
Google Storage Resumable upload fails with CORS error
Yes, I solved it - the problem was that Java does not allow to send / set Origin header with a custom value....
Read more >
CORS errors - HTTP - MDN Web Docs - Mozilla
If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found