0

我的快递应用程序中有这行代码:

 catch (err) {
        res.status(500).send(err.message);
      }

当我控制台记录错误时,我收到此消息:

name: 'TokenExpiredError',
message: 'jwt expired',

但是当我使用 axios 请求在客户端收到错误时,如下所示:

catch (err) {
    console.log(err.message)

我明白了:Request failed with status code 500

如何访问原始按摩?

4

1 回答 1

1

您不想简单地捕获错误,500 错误只是 500 错误(带有它自己的通用消息)。

您需要从响应正文中提取您在响应中发送的消息。这是来自 axios 的 github 问题页面https://github.com/axios/axios/issues/960

axios
.post('ajax/register/otp', this.registerData)
.then(function (response) {
       ...
})
.catch(function (error) {
      console.log(error.response);
 });
于 2019-10-16T15:04:46.797 回答