node.js - Can't send error params to error middleware on an async way in Express -
currently have middleware using express can't launch error same format express uses because it's sync function things next(err) doesn't work.
i send error throw , application not crash it's fine, cant set params such err.message or err.statuscode. code working:
function getscope(req, res, next){ //req.scopesarray array of arrays: [ ['resource','.action'] , ['patient','.create'] ] req.scopesarray.foreach(function(current,index,array){ switch(req.scopesarray){ case 'user': var haspermissions = checkuserpermissions(permissionid,action); break; } if(!haspermissions) throw new error('error permissions'); }); next(); } i've realized that, event not calling next(err), error middleware execute.
i've tried thinks like:
var err = {}; err.message = 'test'; err.statuscode=404; throw new error(err); but has not worked.
how send async error error middleware being able set err values? thanks.
Comments
Post a Comment