-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use error handler #19
Conversation
Is there any reason this isn't merged? Any way to help? |
On second thought, after testing this it doesn't work at all.
Also, this: if (e instanceof UnauthorizedRequestError) {
return res.status(e.code);
} Just leaves the request hanging without resolving it ever at all. |
This code binds
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See review comments.
|
||
res.send({ error: e.name, error_description: e.message }); | ||
res.status(e.code); | ||
if (e instanceof UnauthorizedRequestError) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return res.status(e.code);
leaves the response hanging.
How about:
res.status(e.code);
if (e instanceof UnauthorizedRequestError) {
res.send();
} else {
res.send({ error: e.name, error_description: e.message });
}
if (e instanceof UnauthorizedRequestError) { | ||
return res.status(e.code); | ||
} | ||
if (this.useErrorHandler === true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Down here, this === global
.
We need to either pass useErrorHandler
as an argument or invoke handleError
(and to be consistent handleResponse
) using handleError.call(this, ...)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, updating to use handlerError.call(this, ...)
and handleResponse.call(this, ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not enough. It's nested function, so there will not be this === ExpressOAuthServer
value until you bind this
to the nested function.
I recommend to use strict mode
, so you will see this problem clearly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just realized what you're talking about. The problem is that this
is already wrong by the time handleError.call(this, ...)
is called. Promise.bind(this)
is supposed to help with that, but this
refers to the returned middleware.
This can be solved by changing
var server = this.server;
to
var that = this;
and
return Promise.bind(this)
to
return Promise.bind(that)
in all 3 handlers.
Obviously references to server
have to be replaced by this.server
after this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I see it.. Pushing changes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Bind ExpressOAuthServer context to handleResponse and handleError methods * Fixed bug where particular error never sent
54a886a
to
d63bd43
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See review comments.
return handleError(e, req, res); | ||
}); | ||
return handleError.call(this, e, req, res, null, next); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's two spaces missing.
Add a new option,
useErrorHandler
which will invokenext(err)
if set to true on any errors. If not set or set to false, the library will continue to send the response.