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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
.idea
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ function ExpressOAuthServer(options) {
throw new InvalidArgumentError('Missing parameter: `model`');
}

this.useErrorHandler = options.useErrorHandler ? true : false;
this.useErrorHandler = !!options.useErrorHandler;
delete options.useErrorHandler;

this.continueMiddleware = options.continueMiddleware ? true : false;
this.continueMiddleware = !!options.continueMiddleware;
delete options.continueMiddleware;

this.server = new NodeOAuthServer(options);
Expand Down Expand Up @@ -54,7 +54,7 @@ ExpressOAuthServer.prototype.authenticate = function(options) {
next();
})
.catch(function(e) {
return handleError.call(this, e, req, res, null, next);
return handleError.call(this, e, req, res, null, next, options);
});
};
};
Expand Down Expand Up @@ -88,7 +88,7 @@ ExpressOAuthServer.prototype.authorize = function(options) {
return handleResponse.call(this, req, res, response);
})
.catch(function(e) {
return handleError.call(this, e, req, res, response, next);
return handleError.call(this, e, req, res, response, next, options);
});
};
};
Expand Down Expand Up @@ -122,7 +122,7 @@ ExpressOAuthServer.prototype.token = function(options) {
return handleResponse.call(this, req, res, response);
})
.catch(function(e) {
return handleError.call(this, e, req, res, response, next);
return handleError.call(this, e, req, res, response, next, options);
});
};
};
Expand All @@ -147,9 +147,12 @@ var handleResponse = function(req, res, response) {
* Handle error.
*/

var handleError = function(e, req, res, response, next) {

if (this.useErrorHandler === true) {
var handleError = function(e, req, res, response, next, options) {
var useErrorHandler = this.useErrorHandler;
if (options && 'useErrorHandler' in options) {
useErrorHandler = options.useErrorHandler;
}
if (useErrorHandler === true) {
next(e);
} else {
if (response) {
Expand Down