Skip to content
This repository was archived by the owner on Apr 15, 2023. It is now read-only.

Commit fee0976

Browse files
throws TagMyCodeUnauthorizedException if refresh token is not valid
1 parent 8e15bd3 commit fee0976

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and 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

src/main/java/com/tagmycode/sdk/Client.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

src/main/java/com/tagmycode/sdk/exception/TagMyCodeUnauthorizedException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)