【问题标题】:How to console.log the http response?如何控制台记录http响应?
【发布时间】:2018-10-05 22:57:51
【问题描述】:

我在 get 调用中使用了以下异步等待。如果出现错误,服务器还会发送响应,即文本消息。可以在网络选项卡中看到文本消息。我如何控制台记录该消息,因为它不是 catch-block 中错误的一部分。

callServer = async () => {
    const path = '...';
    try {
      await axios.get(path);
      console.log('successful');
    } catch (error) {
      console.log(error);
    }
  };

【问题讨论】:

  • 我认为消息应该是错误对象的属性。能否在 console.log 行设置断点,查看错误对象中的内容?

标签: javascript async-await


【解决方案1】:

axios的默认是:

console.log(error.response.data);

但这取决于你如何配置 axios。

提示
使用console.dir(error) 查看错误变量中的内容。

【讨论】:

    猜你喜欢
    • 2017-12-23
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    相关资源
    最近更新 更多