-1

I am using React to create an application and using a PHP server for the API. I realized when there is a PHP error i am unable to see what the error is. The only thing i get back is

'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.

Is there anyway where I can see what is the error message from the php side?

json
  • 109
  • 5
  • Does this answer your question? [Response to preflight request doesn't pass access control check](https://stackoverflow.com/questions/35588699/response-to-preflight-request-doesnt-pass-access-control-check) – cbr Jan 19 '21 at 20:12

2 Answers2

0

Actually, the current error message is pretty comprehensive. You need to configure CORS correctly by adding appropriate headers.

Cross-Origin Request Headers(CORS) with PHP headers

Alex Chuev
  • 583
  • 4
  • 15
0

You are getting the CORS issue because your PHP server is running on a different port compared to your react server (react dev server, running on port 3000).

There are two action items to be done in this case:

  1. You may whitelist localhost:3000 on your PHP server (you can check this answer https://stackoverflow.com/a/33090515/13142033).
  2. Use a logger service in your PHP code. For example monolog (https://github.com/Seldaek/monolog). So, you may use a try-catch or generic exception handlers in your PHP code, and whenever there is an error use the logger to write to a file on the disk.

Actually, when you fix the CORS issue, you will see PHP error logs in your react API responses, but having a logger service is a good practice.

code works
  • 26
  • 1
  • 2