-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
@@ -82,7 +82,7 @@ export function request(method, uri, data, options = {}) { | |||
.then( | |||
response => response.body, | |||
err => { | |||
if (err.statusCode == 401) { | |||
if (err.message === 'Unauthorized') { |
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.
Why this change has been introduced ? Does err not have statusCode
field ?
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.
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.
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.
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
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.
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
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 see lack of TypeScript here...
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.
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.
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.
@narma i'm feeling the same, bro
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.
To be honest I didn't get the second question.
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.
Answered in slack
I think we can merge this PR and decide about api-js reusage later |
OK, can I merge it? |
merged ) |
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