Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to let exceptions bubble up instead of passing to finalhandler #2707

Closed
ericuldall opened this issue Jul 16, 2015 · 5 comments
Assignees

Comments

@ericuldall
Copy link

I'm trying to do some exception handling in my app built on express and it's being problematic that every time I throw an exception it gets printed to the screen.

Is this configurable?

@dougwilson
Copy link
Contributor

Are you talking about getting printed to your web browser, or to the console you are running Node.js on?

@ericuldall
Copy link
Author

it does both. I think you just addressed this question on finalhandler issues. Does that answer stand?

@ericuldall
Copy link
Author

basically i'm using process.on('uncaughtException') and my thrown errors aren't getting there.

@dougwilson
Copy link
Contributor

The main two configurations are the following:

// don't print errors on your node console window
app.set('env', 'test')

// don't print errors to your web browser
app.set('env', 'production')

By default Express assumes development mode, which is what causes the stack traces to head to your web browser.

Also by default, Express will dump stack traces to your STDERR handle, which is standard when running the server and redirecting STDERR to an error log (as in node app.js 2> error.log).

I think you just addressed this question on finalhandler issues. Does that answer stand?

Yes, it does :) especially if you want it to be extremely configurable :) Another thing you can do is the following to use finalhandler but turn those two features off:

var express = require('express')
var finalhander = require('finalhandler')
var http = require('http')

var app = express()

// declare things on app

var server = http.createServer(function (req, res) {
  app(req, res, finalhandler(req, res, {
    env: 'production', // no stack traces; option name will be better in 1.0
    onerror: function (err) {
      throw err; // rethrow to your uncaughtException handler, but i _highly_ don't suggest this
    }
  }))
})

server.listen(3000)

@ericuldall
Copy link
Author

thanks again @dougwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants