Learn-by-doing / bitstarter

A crowd funding website that uses bitcoin
MIT License
23 stars 28 forks source link

Stop express errors from leaking #65

Closed bokova closed 7 years ago

bokova commented 7 years ago

I guess we'd like to stop leaking these errors. Eg. not having the proper view lead to the error:

Error: Failed to lookup view "addProject" in views directory "/Users/bo/Documents/NodeJS/bitstarter/views"
   at EventEmitter.render (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/application.js:579:17)
   at ServerResponse.render (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/response.js:960:7)
   at /Users/bo/Documents/NodeJS/bitstarter/controllers/project.js:8:7
   at Layer.handle [as handle_request] (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/layer.js:95:5)
   at next (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/route.js:131:13)
   at Route.dispatch (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/route.js:112:3)
   at Layer.handle [as handle_request] (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/layer.js:95:5)
   at /Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/index.js:277:22
   at Function.process_params (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/index.js:330:12)
   at next (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/index.js:271:10)
   at /Users/bo/Documents/NodeJS/bitstarter/controllers/login.js:33:3
   at Layer.handle [as handle_request] (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/layer.js:95:5)
   at trim_prefix (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/index.js:312:13)
   at /Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/index.js:280:7
   at Function.process_params (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/index.js:330:12)
   at next (/Users/bo/Documents/NodeJS/bitstarter/node_modules/express/lib/router/index.js:271:10)
victorbrender commented 7 years ago

We could go in this direction: https://expressjs.com/en/guide/error-handling.html

bokova commented 7 years ago

Details:

The error is caused by the Express middleware throwing the error

REPRO:

In any controller use a variable / function name that hasn't been initialized. Eg.:

Expected behavior:

Errors should not be leaked to the browser at all but instead logged into the console.