api: report clear error when refresh token is rejected - #362
Open
NanShanFish wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
rbw sync(and any command that needs to refresh the access token) reports a confusing error when the server rejects the stored refresh token:Cause:
exchange_refresh_tokenandexchange_refresh_token_asyncdeserialize the response body unconditionally. When the identity server returns an error like{"error":"invalid_grant"}(HTTP 400), serde fails withmissing field 'access_token', masking the real cause. This is a common real-world scenario: the refresh token has been revoked or has expired (e.g. after changing the master password), leaving the user without an actionable recovery path.Relates to #32.
Changes
src/api.rs: check the response status code before parsing the response in bothexchange_refresh_token*functions. On a non-200 response, parse the standardConnectErrorResand classify it through a newclassify_refresh_token_errorhelper (consistent with the existingclassify_login_errorpattern):invalid_grant→ newError::RefreshTokenInvalidinvalid_client→Error::IncorrectApiKeyError::RequestFailedsrc/error.rs: addError::RefreshTokenInvalid, with an error message telling users how to recover (rbw purgefollowed byrbw login).invalid_grant,invalid_client).Result
Note: this fix targets
doy/rbwupstream; the PR currently lives on the fork.