【问题标题】:How can I get response body for 404 in Axios?如何在 Axios 中获取 404 的响应正文?
【发布时间】:2023-02-15 21:32:54
【问题描述】:

我正在调用一个返回 404 和正文消息的 API。

我想在 Axios 中获取该消息。

我看到了Axios. How to get error response even when api return 404 error, in try catch finally,但它不起作用。

我也试过 error.response.response 但它是未定义的。

如何从 404 获得文本响应?

【问题讨论】:

  • 您的问题非常不清楚,请共享 API 的代码 sn-p(文本)以及您使用 api 的前端
  • @YashSoni,这并不难。 API 返回带有 text/plain 响应类型的 404,我无法从响应正文中获取该文本。

标签: javascript axios


【解决方案1】:

试试https://axios-http.com/docs/handling_errors中设置的例子

特别是:error.message 或 error.response

【讨论】:

  • 这没有用。我试过 error.response.data 但那是空的。
猜你喜欢
  • 1970-01-01
  • 2020-08-10
  • 2019-05-06
  • 2019-01-19
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 2013-07-23
  • 2018-09-27
相关资源
最近更新 更多