This repository was archived by the owner on Apr 15, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed
src/main/java/com/tagmycode/sdk Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
55and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
66
7+ ## UNRELEASED
8+ ### Added
9+ - throws TagMyCodeUnauthorizedException if refresh token is not valid
10+
711## [ 1.2.0] - (2017-11-05)
812### Changed
913- renamed LanguagesCollection and SnippetsCollection
Original file line number Diff line number Diff line change @@ -63,13 +63,21 @@ public void fetchOauthToken(String verificationCode) throws TagMyCodeException {
6363
6464 public void refreshOauthToken () throws TagMyCodeException {
6565 try {
66- setOauthToken (service .getAccessTokenFromRefreshToken (oauthToken .getRefreshToken ()));
66+ fetchAndSetRefreshToken (service .getAccessTokenFromRefreshToken (oauthToken .getRefreshToken ()));
6767 } catch (OAuthException e ) {
68- //TODO if network error: throw unauthenticated only if server has a valid error response
69- throw new TagMyCodeException ("Error fetching refresh token: " + e .getMessage ());
68+ String message = "Error fetching refresh token: " + e .getMessage ();
69+ if (e .getMessage ().contains ("refresh_token" )) {
70+ throw new TagMyCodeUnauthorizedException (message );
71+ } else {
72+ throw new TagMyCodeException (message );
73+ }
7074 }
7175 }
7276
77+ protected void fetchAndSetRefreshToken (OauthToken accessTokenFromRefreshToken ) throws TagMyCodeException {
78+ setOauthToken (accessTokenFromRefreshToken );
79+ }
80+
7381 public String getAuthorizationUrl () {
7482 return service .getAuthorizationUrl (null );
7583 }
Original file line number Diff line number Diff line change @@ -5,4 +5,8 @@ public class TagMyCodeUnauthorizedException extends TagMyCodeException {
55 public TagMyCodeUnauthorizedException () {
66 super ("Unauthorized" );
77 }
8+
9+ public TagMyCodeUnauthorizedException (String message ) {
10+ super (message );
11+ }
812}
You can’t perform that action at this time.
0 commit comments