Skip to content

Commit

Permalink
Do not overwrite access token with empty one
Browse files Browse the repository at this point in the history
  • Loading branch information
seime committed Jan 15, 2024
1 parent 8fdb7bb commit 0bde979
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpResponseException;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.util.BytesContentProvider;
Expand Down Expand Up @@ -125,11 +126,12 @@ public <T> T sendRequestInternal(final Request httpRequest, final AbstractReques
try {
final ContentResponse contentResponse = httpRequest.send();
String newAccessToken = contentResponse.getHeaders().get(HEADER_ACCESS_TOKEN);
if (accessToken == null || !accessToken.equals(newAccessToken)) {
listener.onAccessTokenUpdated(newAccessToken);
if (newAccessToken != null) {
if (accessToken == null || !accessToken.equals(newAccessToken)) {
listener.onAccessTokenUpdated(newAccessToken);
}
accessToken = newAccessToken;
}
accessToken = newAccessToken;

final String responseJson = contentResponse.getContentAsString();
if (contentResponse.getStatus() == HttpStatus.OK_200) {
final JsonObject o = JsonParser.parseString(responseJson).getAsJsonObject();
Expand Down Expand Up @@ -160,6 +162,10 @@ public <T> T sendRequestInternal(final Request httpRequest, final AbstractReques
throw new RestCommunicationException("The operation failed because the bridge (connect) is offline.");
} else if (contentResponse.getStatus() == HttpStatus.TOO_MANY_REQUESTS_429) {
throw new RestCommunicationException("Too many requests, reduce polling time");
} else if (contentResponse.getStatus() == HttpStatus.BAD_GATEWAY_502) {
throw new RestCommunicationException("Gateway trouble at CloudFlare");
} else if (contentResponse.getStatus() == HttpStatus.GATEWAY_TIMEOUT_504) {
throw new RestCommunicationException("Gateway timeout. Yale servers not responding");
} else {
throw new RestCommunicationException("Error sending request to server. Server responded with "
+ contentResponse.getStatus() + " and payload " + responseJson);
Expand Down

0 comments on commit 0bde979

Please sign in to comment.