私はログイン検証に認証サービスを使用していますが、私は無許可(401)応答コードを200にしてメッセージを同じにします。feathers.jsのエラー応答コードを変更できません
私の認証サービスがある
app.service('authentication').hooks({
before: {
create: [
authentication.hooks.authenticate(config.strategies),
function (hook) {
hook.params.payload = {
userId: hook.params.user.userId,
accountId: hook.params.user.accountId
};
return Promise.resolve(hook);
}
],
remove: [
authentication.hooks.authenticate('jwt')
]
},
after: {
create: [ function(hook,next){
hook.result.statusCode = 201;
hook.result.authentication = "user login successful";
next();
}
]
}
});
私のミドルウェア・コードがある
app.use(function(err, req, res, next) {
res.status(err.status || 200);
res.format({
'text/html': function(){
// Probably render a nice error page here
return res.send(err);
},
'application/json': function(){
res.json(err);
},
'text/plain': function(){
res.send(err.message);
}
});
});
私の応答メッセージが
{
"name": "NotAuthenticated",
"message": "Invalid login",
"code": 401,
"className": "not-authenticated",
"data": {
"message": "Invalid login"
},
"errors": {}
}
ですが、私は
{
"name": "NotAuthenticated",
"message": "Invalid login",
"code": 200,
"className": "not-authenticated",
"data": {
"message": "Invalid login"
},
"errors": {}
}
をしたいです210
'res.status(err.status === 401? 200:(err.status || 200) '? – Will
その動作していない@wbadart –