Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

调用不存在的接口导致API崩溃 #1345

Closed
@usagisang

Description

环境

  • 系统/平台: Centos7.3

  • nodejs 版本: 15.14.0

  • API版本: 4.0.20

出现问题

调用某些不存在的接口时(例如仅调用localhost:3000/login),由于answer对象里面的值status和body都是undefined状态,但是在app.js第120行catch错误那里存在一个if语句:

     if (answer.body.code == '301') answer.body.msg = '需要登录'

由于此时body是undefined,无法找到code属性,因此应用崩溃,需要进行重启。

重现步骤

调用/login或者/login/img等接口均可重现错误,报错信息如下:

[ERR] /login { status: undefined, body: undefined }
/home/admin/MusicApi/app.js:120
          if (answer.body.code == '301') answer.body.msg = '需要登录'
                          ^

TypeError: Cannot read property 'code' of undefined
    at /home/admin/MusicApi/app.js:120:27

期待效果

望修复

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions