Skip to content
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

added /login redirect in case of error 401 from API #757

Merged
merged 2 commits into from
Jan 30, 2017

Conversation

bagratinho
Copy link
Contributor

Fixed the bug with invalid JWT.
When API call responds 401 error, system now redirects user to /admin/login page.
https://trello.com/c/4sNkIU69

@@ -82,7 +82,7 @@ export function request(method, uri, data, options = {}) {
.then(
response => response.body,
err => {
if (err.statusCode == 401) {
if (err.message === 'Unauthorized') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change has been introduced ? Does err not have statusCode field ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err is an instance of Error object, and it appeared that it doesnt have statusCode field.
Only accessible parameter allowing to determine the error type is the message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually err has status field which you could use. (but not statusCode, I think statusCode has been added when we have isomorphic-fetch instead of superagent). https://github.com/visionmedia/superagent/blob/master/lib/client.js#L426

And err.message is equals to response.statusText so, I think both approaches could work here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what about fixing this bug in api-js and reuse this library here instead of fixing bugs it two places at one time ? cc @jmataya

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see lack of TypeScript here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I'd better change the if statement to check the err.status instead of message, its better to stick to how it was done originally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@narma i'm feeling the same, bro

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I didn't get the second question.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered in slack

@bagratinho bagratinho added the WIP label Jan 30, 2017
@anru
Copy link
Contributor

anru commented Jan 30, 2017

I think we can merge this PR and decide about api-js reusage later

@bagratinho
Copy link
Contributor Author

OK, can I merge it?

@anru anru merged commit 2268273 into master Jan 30, 2017
@anru anru deleted the bug/401-error-handling branch January 30, 2017 16:41
@anru
Copy link
Contributor

anru commented Jan 30, 2017

merged )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants