0

I'm trying to catch in JS and log to Sentry an error thrown when doing AJAX GET request to the API where CORS is disabled. I can't get the error message in jQuery fail() function nor in $(document).on({ajaxError:...}). The only content of my xhr object is {"readyState":0,"withCredentials":true,"status":0,"statusText":"error"} I see, however, the following messages in my console: Error

Access to XMLHttpRequest at 'https://***/' from origin 'https://***' has been blocked by CORS policy: Response to reflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

thrown by my HTML file, and a warning

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://***/ with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.

thrown by raven.js. Is there any option to capture these messages in JS as they are seen in colsole?

I'd like to underline, that I don't want to get rid of CORS error (set *, etc). I just want to catch it.

Niko
  • 812
  • 9
  • 22
  • 1
    Possible duplicate or maybe this should help you : https://stackoverflow.com/questions/6970475/get-all-javascript-errors-on-page-javascript-error-handling – arielb Mar 06 '19 at 12:35
  • @arielb, thanks for the answer, but this is for redirecting all console messages. I wonder if there is a chance to catch this one. – Niko Mar 06 '19 at 12:37
  • Not really sure but if anything can catch this it's this: https://docs.sentry.io/error-reporting/security-policy-reporting/ – Markus Unterwaditzer Mar 06 '19 at 13:27
  • 1
    See the answer at https://stackoverflow.com/questions/42721584/catching-an-access-control-allow-origin-error-in-javascript/42723074#42723074. The gist of it is, The details of errors for XHR and Fetch API requests are not exposed to frontend JavaScript, by design, for security reasons. – sideshowbarker Mar 12 '19 at 12:03
  • Thank you @sideshowbarker. I consider this question as answered. – Niko Mar 13 '19 at 07:05

0 Answers0