Skip to content

Commit

Permalink
options.errorHandler and options.pageNotFound use in http.Server, in …
Browse files Browse the repository at this point in the history
…connect, just use next
  • Loading branch information
rockdai committed Sep 12, 2012
1 parent 4388e29 commit 0268ac2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion coverage.html

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions lib/urlrouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ function router(fn, options) {
options = options || {};
options.paramsName = options.paramsName || 'params';
options.pageNotFound = options.pageNotFound || pageNotFound;
options.errorHandler = options.errorHandler || '';
options.errorHandler = options.errorHandler || errorHandler;

function createMethod(name) {
var localRoutes = routes[name.toUpperCase()] = [];
return function (urlpattern, handle) {
var middleware = [];
var middleware = null;

// slice middleware
if (arguments.length > 2) {
Expand Down Expand Up @@ -100,9 +100,7 @@ function router(fn, options) {
var routeMiddleware = function (err) {
var mw = middleware[k++];
if (err) {
var errHandler = options.errorHandler ? options.errorHandler :
next ? next :
errorHandler;
var errHandler = next || options.errorHandler;
return errHandler(err, req, res);
} else if (mw) {
return mw(req, res, routeMiddleware);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ exports.createRouter = function (urlpattern) {
* @api private
*/

exports.flatten = function(arr, ret){
exports.flatten = function (arr, ret) {
ret = ret || [];
var len = arr.length;
for (var i = 0; i < len; ++i) {
Expand Down
6 changes: 3 additions & 3 deletions test/urlrouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ describe('use connect with options.errorHandler()', function () {
after(function () {
app.close();
});
it('should using custom error handler', function (done) {
it('should using next first', function (done) {
app.request().get('/error').end(function (res) {
res.should.status(200);
res.body.toString().should.equal('oh no, error occurred on /error');
res.should.status(500);
res.body.toString().should.include('Some more Error');
done();
});
});
Expand Down
6 changes: 3 additions & 3 deletions test_results.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,12 @@ app.request().get('/error').end(function (res) {

<a name="use-connect-with-optionserrorhandler" />
# use connect with options.errorHandler()
should using custom error handler.
should using next first.

```js
app.request().get('/error').end(function (res) {
res.should.status(200);
res.body.toString().should.equal('oh no, error occurred on /error');
res.should.status(500);
res.body.toString().should.include('Some more Error');
done();
});
```
Expand Down

0 comments on commit 0268ac2

Please sign in to comment.