about Error-agent
error agent is a module help you deal with the errors, and respond them to http client
install
npm install error-agent
how to use
when dealing with errors, many people simply use string, instead of Error object, which is not appropiate
you need to use Error object, attached with some properties, so you know how to deal with it later
so, when you're in async code
var errorAgent= ; DB
or simply throw
if!userDataauth throw errorAgent;
as you might guess, errorAgent.handle
return an Error object
with the properties you pass in
send error message to client
you should call it at your last callback
and pass the error object to use
, pass req
, res
to send
it will deal with it for you
errorAgent;
code
property
using you can use code property, so you can register a function to deal with certain error code
ifuserhasNoName throw errorAgent;
register a code error handler first
ErrorAgent;
use error file instead of register
just give a file path, that will exports error code handlers
would be better
ErrorAgent
express example
todo
- error page folder path