Closed mkilp closed 10 months ago
@mkilp did you have the same problem with previous versions of the library or this is after updating to latest?
Hello, @mkilp 👋. I believe the client-side library behaves as expected here based on the issue description. Due to CORS constraints, the client-side JavaScript code cannot access the details of a preflight request. When a preflight request fails, the JavaScript library only knows it's a networking error. It also aligns with the spec for fetch API.
For best practices to prevent the preflight requests from getting throttled, can you reach out to the API Gateway service team. I'm not sure if there's much on the Amplify side that can be done here.
Hi @cwomack, thanks for the response!
I actually took your hint and manually excluded the OPTIONS route inside API gateway from throttling. However I am still facing the same issue weirdly enough. If I send a manual preflight OPTIONS call to my API route via Postman I get a normal 200 response. Chrome / amplify however returns 429 too many requests on the preflight request which causes the low level network error again. After I deployed my throttle exception it worked for a hot second before going back to not working again.
While using my webapp and post man at the same time I could see postman switching from 429 to 200 running the OPTIONS request while the webapp keeps getting 429. I'm honestly at a loss and also reached out to the api gateway team. However since the requests succeed in Postman I am not sure how they will be able to help.
@elorzafe I had the issue both with an old version and latest.
Hi @cwomack I actually take it back, the follow up error was on my end with a wrong api url.
Manually overriding the throttle inside API gateway for the OPTIONS route solved the issue for me for anyone reading this.
Thanks for your help!
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
REST API
Amplify Categories
api
Environment information
Describe the bug
My API gateway is enabled with rate limiting and returns error code 429 (built in function) when the limit is hit. This causes the OPTIONS request to fail from amplify. This in turn then causes my browser to reject the request due to a cors error:
Access to XMLHttpRequest at 'https:/xxx/stage/me' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
This then causes amplify-js to return a generic AXIOS network error instead of a proper one with http status and co:
[DEBUG] 34:56.825 RestClient AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}code: "ERR_NETWORK"config: {transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}message: "Network Error"name: "AxiosError"request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}stack: "AxiosError: Network Error\n at XMLHttpRequest.handleError (http://localhost:3000/static/js/vendors~main.chunk.js:4891:14)"
I am not sure if its because chrome blocks the request or because the options request fails - but it is very frustrating.
I have added all cors headers to the options route:
I am not sure if I am missing some step to be able to detect a rate limited api call and display an error.
Expected behavior
amplify provides me a proper error with the error code.
Reproduction steps
Set up a blank amplify project and set the rate limits on a route to 0 for rate and burst.
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response