返回之前,我继承了一些非常凌乱环回代码,我想知道是否有可能超过200设置状态码回送
返回的状态码例如,我有以下代码:
PensionsUser.loginView = function (ctx, credentials, cb) {
var respJSON = util.getresponseTemplate();
credentials.email = credentials.email.toLowerCase().trim();
PensionsUser.login(credentials, 'user', function (err, loginResp) {
if (err) {
util.addErrorToResponse(err, respJSON, 'NO-PUS-LV-001');
app.log.error(util.loggingTemplate('PensionsUser', 'loginView', 'NO-PUS-LV-001', credentials.email));
ctx.res.status = 401; //does not work
cb(null, respJSON);
//etc.
我知道cb(null, respJSON)
应该返回错误这样cb(respJSON)
但遗憾的是前端代码依赖于如目前正在返回此JSON是,所以我的第一个步骤将是刚刚更改的状态代码。
这可能吗?