Parse Error response in Express NodeJS app

泄露秘密 提交于 2020-01-06 08:45:08

问题


I am trying to send a specific error message to my front end.

Scenario 1

app.use(function(err, req, res, next){
    console.log(err);
});

logs: [String: 'Error: Request returned error code: 422 and body: {"status":422,"title":"Missing or incorrect required fields","type":"https://developer.bigcommerce.com/api#api-status-codes","errors":{"variant":"This product has options, variant ID is required"}}']

Scenario 2

app.use(function(err, req, res, next){
    res.status(422).send('TEST TEST TEST');
});

Scenario 3

app.use(function(err, req, res, next){
    res.status(422).send(err); //Same "err" as scenario 1
});

Summary

In scenarion 3 I expected to see what was logged in scenario 1 on the frontend. Can someone help me send the variant message (from scenario 1) to the frontend

来源:https://stackoverflow.com/questions/50159041/parse-error-response-in-express-nodejs-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!