【问题标题】:Why Axios logs error 403 even when I catch it为什么即使我发现 Axios 也会记录错误 403
【发布时间】:2018-03-02 19:12:46
【问题描述】:

基于 axios 文档,我在请求之后有 catch 块,但即使我捕捉到错误并显示警报,在浏览器控制台上我也收到了消息:

POST http://localhost:5000 403 (Forbidden)      spread.js:25

为什么上面的消息? 这是默认浏览器行为吗?

客户:

axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    alert(error);
  });

服务器:

res.status(403).send('Error message');

【问题讨论】:

  • spread.js 是 Axios 源代码中的“用于调用函数和扩展参数数组的语法糖”模块。传递给它的函数可能正在执行您注意到的控制台日志记录。

标签: javascript express axios


【解决方案1】:

是的,至少 Chrome 默认会记录每个失败的 http 请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 2021-12-02
    • 2021-07-02
    • 2014-04-01
    • 2015-03-08
    相关资源
    最近更新 更多