Storage API doesn't throw error even if the CORS error
See original GitHub issueBefore opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
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:
- Created 2 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for reporting. Looking into this issue now
Facing the same issue.
Even if you go offline in between an upload, the Storage.put promise is resolved. Should throw an error.