Skip to content

Commit d63bd43

Browse files
author
Michael Salinger
committed
Code review fixes:
* Bind ExpressOAuthServer context to handleResponse and handleError methods * Fixed bug where particular error never sent
1 parent de9a417 commit d63bd43

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ExpressOAuthServer.prototype.authenticate = function(options) {
5252
next();
5353
})
5454
.catch(function(e) {
55-
return handleError(e, req, res, null, next);
55+
return handleError.call(this, e, req, res, null, next);
5656
});
5757
};
5858
};
@@ -80,10 +80,10 @@ ExpressOAuthServer.prototype.authorize = function(options) {
8080
res.locals.oauth = { code: code };
8181
})
8282
.then(function() {
83-
return handleResponse(req, res, response);
83+
return handleResponse.call(this, req, res, response);
8484
})
8585
.catch(function(e) {
86-
return handleError(e, req, res, response, next);
86+
return handleError.call(this, e, req, res, response, next);
8787
});
8888
};
8989
};
@@ -111,10 +111,10 @@ ExpressOAuthServer.prototype.token = function(options) {
111111
res.locals.oauth = { token: token };
112112
})
113113
.then(function() {
114-
return handleResponse(req, res, response);
114+
return handleResponse.call(this, req, res, response);
115115
})
116116
.catch(function(e) {
117-
return handleError(e, req, res, response, next);
117+
return handleError.call(this, e, req, res, response, next);
118118
});
119119
};
120120
};
@@ -141,11 +141,13 @@ var handleError = function(e, req, res, response, next) {
141141
res.set(response.headers);
142142
}
143143

144+
res.status(e.code);
145+
144146
if (e instanceof UnauthorizedRequestError) {
145-
return res.status(e.code);
147+
return res.send();
146148
}
147149

148-
res.status(e.code).send({ error: e.name, error_description: e.message });
150+
res.send({ error: e.name, error_description: e.message });
149151
}
150152
};
151153

0 commit comments

Comments
 (0)