Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions templates/js/app.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ app.use(function(req, res, next) {

// error handler
app.use(function(err, req, res, next) {
if (res.headersSent) {
return next(err);
}

// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
Expand Down
8 changes: 8 additions & 0 deletions test/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ describe('express(1)', function () {
assert.strictEqual(typeof app.handle, 'function')
})

it('should delegate errors after headers are sent', function () {
var file = path.resolve(ctx.dir, 'app.js')
var contents = fs.readFileSync(file, 'utf8')

assert.ok(contents.indexOf('if (res.headersSent) {') !== -1)
assert.ok(contents.indexOf('return next(err);') !== -1)
})

describe('npm start', function () {
before('start app', function () {
this.app = new AppRunner(ctx.dir)
Expand Down