问题
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