Houston, we have a problem - express middleware
A small library for displaying errors from express
npm install --save howhap
app.js
let express = ;let howhap = ; // An *optional* preset list of errors.let options = errors: DEFAULT: message: 'An unknown error occurred.' status: 500 level: 'error' // this property specified what // level of logging is associated // with this error. AUTH: INVALID_EMAIL: message: '{{ email }} is not a valid email.' status: 400 MISSING_PASSWORD: message: 'Please enter a password.' status: 400 defaultFormat: 'json' // If no response format is supplied, // responses will be in this format. logging: // options for winston loggin go here ; let app = ; // Pass in the option argument to customize the behavior // of the middleware. Alternatively you can pass in nothing// and use the default behavior.app;
example route
let express = ;let router = express;let validator = ; router;
example view
Log in Log in <!-- - An `error` object is passed to all views, with a - display method. The first argument is the key - of the error that you'd like to display. The - second (optional) argument is a default value - that you'd like to display if there is no error - for the specified key. --> <%= error.display('email') %> <!-- - A `prev` object is also passed to all views, - which stores the previous data that was posted - (body, query, and params). This data is only set - if there was an error. It takes two arguments - (the type of data and the key) as well as an - optional third argument if there was no data - found for that particular key. --> <!-- Example of using the optional default (second argument) --> <%= error.display('email', 'Bad password') %> Log in