-
Notifications
You must be signed in to change notification settings - Fork 51
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
Handle errors in OAuth endpoint #27
Conversation
const { | ||
data: { access_token: token, scope } | ||
} = await request(route, parameters); | ||
} = response; |
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.
Instead of throwing a custom error, I'd simulate the behavior that would occur if the server responded with a 400 status code. I've created https://github.com/octokit/request-error.js for cases such as this.
The code would look sth like this
throw new RequestError(`${response.data.error_description} (${response.data.error})`, 400, {
headers: response.headers,
request: request.endpoint(route, parameters)
});
That way the error can be handled just like other errors such as server outages or request timeouts
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.
I implemented this change but used response.status
(which will be 200
) rather than 400
... Because it doesn't sound like a good idea to fake the status code like that. Let me know if you disagree.
Edit: Reading more carefully I see that you had explicitly suggested emulating a 400
status code. I don't have enough context to understand what is or isn't a good idea here. I'll just do whatever you tell me.
There is a type error that should be fixed by octokit/request-error.js#17. |
f4d7618
to
a8d36c4
Compare
I've rebased on latest master and bumped |
Could you do me a favor and apply the same fix to |
🎉 This PR is included in version 2.4.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fixes #26.
I've added a test and a fix. Let me know if you had something else in mind.
Jest is reporting missing branch coverage because I'm not testing the default value in case the response does not include an
error_description
. I introduced the default value just in case, but the documentation I could find seems to always includeerror_description
, so maybe it's not necessary.