Getting CORS issue while accessing the error object in react

Viewed 38

i have a client running at 9000 port and a rails server running at 3000 port so my rails server is CORS enabled using rack-cors gem. so basically the rails server running in 3000 port provide the react assets to the client running at 9000 port.

the component looks like below

Import ErrorComponent form './...'

<ErrorComponent> <Main Component/> </ErrorComponent>

so when react component gets rendered in 9000 port it is wrapped by a component which handles error (i.e ErrorComponent). so now when the error occurs in 9000 port the error object is passed above to the component handling error who's code is present in server 3000 port (i.e rails server). so now the error is displayed as CORS error. 'Error: A cross-origin error was thrown. React doesn't have access to the actual error object in development.'

my cors handling in the rails-server is as below

allow do origins '*' resource '*', headers: :any, credentials: false, methods: %i[get post options delete] end

our request to the 3000 port is having the CORS headers in the response mentioned here https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin. but no luck.

let me know if anyone has any suggestions for the above issue.

0 Answers
Related