senchalabs/connect — Issue #503: Request for assistance with errorHandler()
Author: boozedog
Created: 2012-03-06 14:00:29+00:00
State: open

Hi there, I'm playing with errorHandler and having some trouble figuring it out.

Consider the following code:
```javascript
var connect = require('connect');
var app = connect()
//.use(connect.errorHandler())
.use(function(req, res) {
var x = JSON.stringify(req); // this line will crash
res.write('this is a test');
res.end(req.url);
})
.listen(8080);
```

When I run this, and visit the page, I get a text/plain stacktrace along with a 500 HTTP error code. So far so good.

BUT when I un-comment the `.use(connect.errorHandler())` I don't see any change in the behavior of the app ... still seeing text/plain stacktrace. Was expecting pretty HTML stacktrace or something?

What's more, if I swap two lines:
```javascript
.use(function(req, res) {
res.write('this is a test');
var x = JSON.stringify(req); // this line will crash
res.end(req.url);
})
```
Now the app outputs nothing to the browser at all (but I still see the stack trace in the console.log).

I even threw a couple console.log statements into node_modules/connect/lib/middleware/errorHandler.js to see what's going on but it doesn't appear the code in that middleware ever executes.

I've tried The Google but not finding much in the way of documentation ... can anyone assist?

Thanks!