如何在JavaScript中获取CORS / CORB错误消息?

时间:2019-03-06 12:32:46

标签: javascript ajax error-handling cors sentry

我正在尝试捕获JS并登录到Sentry,当对禁用了GET的API进行AJAX CORS请求时,抛出了一个错误。我在jQuery fail()函数和$(document).on({ajaxError:...})中都未收到错误消息。我的xhr对象的唯一内容是{"readyState":0,"withCredentials":true,"status":0,"statusText":"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.

我的HTML文件抛出了一个警告

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.
raven.js投掷

。 像在鞋底中看到的那样,是否有任何选项可以在JS中捕获这些消息?

我想强调一下,我不想摆脱CORS错误(设置*等)。我只想抓住它。

1 个答案:

答案 0 :(得分:-2)

这里是类似的问题-Cross-Origin Read Blocking (CORB), 回答了the CORB error message can be safely ignored