【发布时间】:2016-08-05 15:37:05
【问题描述】:
我正在尝试使用自己的远程方法来重置密码。用户只需将电子邮件放在路径中,服务器将发送 accessToken 作为响应。
MyUser.remoteMethod('requestPasswordReset',
{
http: {path: '/reset/:usermail', verb: 'post'},
accepts: [{arg: 'usermail', type: 'string', required: true, http: {source: 'path'}}],
returns: {root: true, type: 'object'},
description: 'Allows Users to request a password reset, returns an error if the specified email does not exist'
}
);
MyUser.requestPasswordReset = function (usermail, next) {
MyUser.resetPassword({email: usermail}, function (err) {
if (err) {
next(err);
}
else {
MyUser.on('resetPasswordRequest', function (info) {
console.log('next will be executed, but crashes the second time');
next(null, info.accessToken.id);
});
}
})
};
我第一次向/reset/:usermail 发出请求时一切正常,但第二次运行请求时应用程序崩溃并出现以下错误
发送后无法设置标头
我知道调用更多回调时通常会发生此错误。
如果我给回调一个其他错误参数。例如next('abc') 而不是 null next(null, info.accessToken.id); 应用程序不会崩溃
【问题讨论】:
标签: node.js callback loopbackjs strongloop