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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -