-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Bubble API errors up. #588
Conversation
return response; | ||
}) | ||
.then(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.
Linter wanted a blank line 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.
If you move the comment to be outside of the .then()
then the blank line before the comment will look nicer
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.
Better to update the linter to not complain about this when the comment in one level more indented than the previous line
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.
Couldn't find a rule in the linter that would make this pass. Ended up removing the comment, since (imo) it doesn't add a ton to this function overall
src/lib/API.js
Outdated
@@ -105,12 +105,13 @@ function createLogin(login, password) { | |||
* @returns {Promise} | |||
*/ | |||
function queueRequest(command, data) { | |||
return new Promise((resolve) => { | |||
return new Promise((resolve, reject) => { | |||
// Add the write request to a queue of actions to perform | |||
networkRequestQueue.push({ | |||
command, | |||
data, | |||
callback: resolve, |
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 make this code a little more consistent, rename callback
to resolve
.
src/lib/API.js
Outdated
@@ -237,6 +210,9 @@ function request(command, parameters, type = 'post') { | |||
if (parametersWithAuthToken.doNotRetry !== true) { | |||
queueRequest(command, parametersWithAuthToken); | |||
} | |||
|
|||
// Throw an error so we can pass the error up the chain | |||
throw new Error(); |
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.
Specify an error message with this error so it's not just a generic error.
src/lib/API.js
Outdated
throw new Error(response.message); | ||
} | ||
|
||
// Update the authToken so it's used in the call to createLogin below |
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.
// Update the authToken so it's used in the call to createLogin below | |
// Update the authToken so it's used in the call to createLogin below |
return response; | ||
}) | ||
.then(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.
If you move the comment to be outside of the .then()
then the blank line before the comment will look nicer
src/lib/API.js
Outdated
.finally(() => { | ||
Ion.merge(IONKEYS.SESSION, {loading: false}); | ||
}); |
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.
.finally(() => { | |
Ion.merge(IONKEYS.SESSION, {loading: false}); | |
}); | |
.finally(() => Ion.merge(IONKEYS.SESSION, {loading: false})); |
# Conflicts: # src/lib/API.js
Updated |
Updated |
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.
LGTM
src/lib/API.js
Outdated
// If the request failed, we need to put the request object back into the queue as long as there is no | ||
// doNotRetry option set in the parametersWithAuthToken | ||
if (parametersWithAuthToken.doNotRetry !== true) { | ||
queueRequest(command, parametersWithAuthToken); | ||
} | ||
|
||
// If we already have an error, throw that so we do not swallow it | ||
if (error && error instanceof Error) { |
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.
error &&
seems unnecessary
Updated, removed the extra check that wasn't needed |
# Conflicts: # src/lib/API.js
Merge conflicts resolved. |
Requested changes were made and Tim is OOO, dismissing
@marcaaron and @cead22 will you review please?
Fixed Issues
Fixes https://github.com/Expensify/Expensify/issues/142656
Tests
Screenshots
n/a