Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
fix: fix refresh token fail
Browse files Browse the repository at this point in the history
  • Loading branch information
xionghan.00 committed Jan 7, 2020
1 parent 48b0f6a commit ef0abfa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void refreshTenantToken(String tenantKey) throws LarkClientException {
try {
AppTenantAccessToken appTenantAccessToken = newTask.get();
if (appTenantAccessToken != null) {
LoggerUtil.GLOBAL_LOGGER.debug("token refreshed for appId: {}, tenantKey: {}", app.getAppId(), tenantKey);
tenantTokenMap.put(tenantKey, appTenantAccessToken);
}
} catch (InterruptedException e) {
Expand All @@ -156,6 +157,8 @@ public void refreshTenantToken(String tenantKey) throws LarkClientException {
} else {
throw new RuntimeException(e.getCause());
}
} finally {
tenantTokenFetchFutureMap.remove(tenantKey, newTask);
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class HttpException extends Exception {
public HttpException(int httpCode, String response) {
super(response);
this.httpCode = httpCode;
this.response = response;
this.response = String.valueOf(response);
}

public HttpException(Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String doPostFile(String url, int connectTimeout, int readTimeout, Map<St

multiPartHttpRequester.finish();

String respStr = streamToString(conn.getInputStream());
String respStr = responseAsString(conn);
checkHttpCode(conn.getResponseCode(), respStr);
return respStr;

Expand Down Expand Up @@ -72,7 +72,7 @@ private String doRequest(String url, int connectTimeout, int readTimeout, Map<St
conn.setRequestMethod("GET");
}

String respStr = streamToString(conn.getInputStream());
String respStr = responseAsString(conn);

checkHttpCode(conn.getResponseCode(), respStr);

Expand Down Expand Up @@ -110,7 +110,18 @@ private HttpURLConnection newHttpConnection(String url, int connectTimeout, int
return conn;
}

private String streamToString(InputStream is) throws IOException {
private String responseAsString(HttpURLConnection conn) throws IOException {
InputStream is;
try {
is = conn.getInputStream();
} catch (IOException e) {
is = conn.getErrorStream();
}

if (is == null) {
return null;
}

final StringBuilder response = new StringBuilder();
try (BufferedReader in = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
String inputLine;
Expand Down

0 comments on commit ef0abfa

Please sign in to comment.