-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restify support and httpError route.
- Loading branch information
Eric Elliott
committed
Oct 20, 2013
1 parent
5e534bd
commit 54f04ed
Showing
8 changed files
with
201 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
var restify = require('restify'), | ||
server = restify.createServer(), | ||
|
||
handleError = function handleError() { | ||
console.log('Caught error!'); // never hserverens | ||
setTimeout(function () { | ||
process.exit(1); | ||
}, 3000); | ||
}, | ||
|
||
middlewareError = | ||
function middlewareError() { | ||
throw new Error('Random middleware error.'); | ||
}; | ||
|
||
|
||
server.get('/err', function (req, res, next) { | ||
// This doesn't get caught. | ||
next( new Error('Random unrecoverable error. ' + | ||
'Server is now running in undefined state!') ); | ||
}); | ||
|
||
server.get('/thrower', function () { | ||
// This doesn't get caught. | ||
throw new Error('Random unrecoverable error. ' + | ||
'Server is now running in undefined state!'); | ||
}); | ||
|
||
// This gets caught, yay! | ||
server.use(middlewareError); | ||
|
||
server.get('/middleware', function () { | ||
// Placeholder to invoke middlewareError. | ||
}); | ||
|
||
// This works for middleware. Fails for routes. | ||
server.on('uncaughtException', handleError); | ||
|
||
// Nope. This doesn't help. | ||
process.on('uncaughtException', handleError); | ||
|
||
server.listen(3000, function () { | ||
console.log('Listening on port 3000'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use strict'; | ||
|
||
var express = require('express'), | ||
errorHandler = require('../error-handler.js'), | ||
app = express(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
var restify = require('restify'), | ||
server = restify.createServer(), | ||
errorHandler = require('../error-handler.js'), | ||
|
||
handleError = errorHandler({ | ||
server: server | ||
}), | ||
|
||
middlewareError = | ||
function middlewareError() { | ||
throw new Error('Random middleware error.'); | ||
}; | ||
|
||
|
||
server.get('/err', function (req, res, next) { | ||
// This doesn't get caught. | ||
next( new Error('Random unrecoverable error. ' + | ||
'Server is now running in undefined state!') ); | ||
}); | ||
|
||
server.get('/thrower', function () { | ||
// This doesn't get caught. | ||
throw new Error('Random unrecoverable error. ' + | ||
'Server is now running in undefined state!'); | ||
}); | ||
|
||
// This gets caught, yay! | ||
server.use(middlewareError); | ||
|
||
server.get('/middleware', function () { | ||
// Placeholder to invoke middlewareError. | ||
}); | ||
|
||
handleError( | ||
{req: true}, | ||
{ | ||
res: true, | ||
send: function () {} | ||
}, | ||
{route: true}, | ||
new Error('Testing handleError') | ||
); | ||
|
||
server.on('after', handleError); | ||
|
||
process.on('uncaughtException', handleError); | ||
|
||
server.listen(3000, function () { | ||
console.log('Listening on port 3000'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters