Skip to content

Commit

Permalink
fix(helix): read remaining header from correct object (#728)
Browse files Browse the repository at this point in the history
* fix(helix): read remaining header from correct object

* fix: doubly ensure response is closed
  • Loading branch information
iProdigy committed Feb 16, 2023
1 parent d6c6f4c commit 19e94e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -16,7 +16,6 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.exception.ContextedRuntimeException;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

Expand Down Expand Up @@ -101,8 +100,10 @@ public Exception decode(String methodKey, Response response) {
.addContextValue("errorType", error.getMessage())
.addContextValue("errorMessage", error.getMessage());
}
} catch (IOException fallbackToDefault) {
} catch (Exception fallbackToDefault) {
ex = defaultDecoder.decode(methodKey, response);
} finally {
response.close();
}

return ex;
Expand Down
Expand Up @@ -11,6 +11,7 @@
import static com.github.twitch4j.helix.interceptor.TwitchHelixClientIdInterceptor.AUTH_HEADER;
import static com.github.twitch4j.helix.interceptor.TwitchHelixClientIdInterceptor.BEARER_PREFIX;
import static com.github.twitch4j.helix.interceptor.TwitchHelixClientIdInterceptor.CLIENT_HEADER;
import static com.github.twitch4j.helix.interceptor.TwitchHelixHttpClient.getFirst;
import static com.github.twitch4j.helix.interceptor.TwitchHelixHttpClient.getFirstHeader;
import static com.github.twitch4j.helix.interceptor.TwitchHelixHttpClient.getFirstParam;

Expand All @@ -32,7 +33,7 @@ public Object decode(Response response, Type type) throws IOException {
String token = getFirstHeader(AUTH_HEADER, request);
if (token != null && token.startsWith(BEARER_PREFIX)) {
// Parse remaining
String remainingStr = getFirstHeader(REMAINING_HEADER, request);
String remainingStr = getFirst(REMAINING_HEADER, response.headers());
Integer remaining;
try {
remaining = Integer.parseInt(remainingStr);
Expand Down

0 comments on commit 19e94e1

Please sign in to comment.