This library is made of the following components:
httboom.AppErrorfor application errors (e.g.: invalid response from backends, db errors)
httboom.UserErrorfor user errors (e.g.: missing or invalid user inputs)
Both constructors accept the same parameters, here is an almost-complete example:
// add, as the last middlewareapp
This connect / express middleware will handle errors passed via
insert as the last middleware, after any 404 handler.
It will log the error message, the stack trace and optionally prints additional information by using
additionalLoggingFn (you may want to print current logged user's details,...).
You should provide an
error template to be rendered, see
The following logic will be applied when rendering an error response:
if 'html' in reqheadersaccept# renders an 'error' templateif is_user_error and reqflash# uses flash middleware and redirects backreqflash 'error'errmessageresredirect refererelse# renders an 'error' templateresrender 'error'error_dataelse if 'json' in reqheadersaccept# renders json responseresjson error_data;else# text-only (e.g. for wget / curl)resenderror_datamessage + ' + ' + error_dataerrlogid
examples/example.js for a working example (you'll need to set a
LOGENTRIES_APIKEY env variable).
Before running the examples you should install module's dev dependencies.
Copyright © 2013 Simone Lusenti firstname.lastname@example.org, Plastic Panda
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.