Node.js 无法从error.message中提取错误消息

Node.js 无法从error.message中提取错误消息,node.js,express,error-handling,axios,Node.js,Express,Error Handling,Axios,我的express应用程序中有以下代码行: catch (err) { res.status(500).send(err.message); } 当我记录错误时,我收到以下消息: name: 'TokenExpiredError', message: 'jwt expired', 但当我使用axios请求在客户端收到错误时,如下所示: catch (err) { console.log(err.message) 我发现:请求失败,状态代码为500 如何

我的express应用程序中有以下代码行:

 catch (err) {
        res.status(500).send(err.message);
      }
当我记录错误时,我收到以下消息:

name: 'TokenExpiredError',
message: 'jwt expired',
但当我使用axios请求在客户端收到错误时,如下所示:

catch (err) {
    console.log(err.message)
我发现:
请求失败,状态代码为500


如何访问原始按摩?

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

您需要从响应正文中提取响应中发送的消息。这来自axios的github发布页面:

axios
.post('ajax/register/otp', this.registerData)
.then(function (response) {
       ...
})
.catch(function (error) {
      console.log(error.response);
 });