How i can manage all error of my restful server build with Restify of NodeJS? For example internal errors, database errors, validate, required params, not founds, athorizeds... And uncaughtException and return custom response to browser?
How i can design the share of data and errors between controllers?
Thanks
I had the requirement to build up a REST API in node. js and was looking for a more light-weight framework than express. js which probably avoids the unwanted features and would act like a custom-built framework for building REST APIs. Restify from its intro is recommended for the same case.
Restify is a framework built specifically to build REST web services in Node. js frameworks such as Express. js and Hapi. Restify manages such difficult tasks as versioning, error handling, and content negotiation.
restify optimizes for introspection and performance, and is used in some of the largest Node. js deployments on Earth.
next(err)
really means res.send(err)
. It's not an alternative to throw err
. If you need to log and shut down, pass it off to an error handling module instead of stuffing it in next(err)
where it will be swallowed.server.on('uncaughtException'...
is how you handle any errors that were thrown in middleware / routes. It works fine for that purpose, as long as you remember the first guideline. 'uncaughtException'
will not be triggered for next(err)
calls.
formatters
are the way to customize error messages going out to the users. They're definitely not a viable alternative to dealing with errors in uncaughtException
, because presumably, once you get there, you're sending the user the error you want them to see... not necessarily the error that was originally generated. See point 1.process.on('uncaughtException'...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With