1
0
mirror of https://github.com/square/okhttp.git synced 2025-11-27 18:21:14 +03:00

Handle UnsupportedCharsetException in HttpLoggingInterceptor

This commit is contained in:
Dave Roberge
2016-01-16 15:32:09 -05:00
parent c193481e6d
commit fc238a225d
2 changed files with 50 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ package okhttp3.logging;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.concurrent.TimeUnit;
import okhttp3.Connection;
import okhttp3.Headers;
@@ -227,7 +228,15 @@ public final class HttpLoggingInterceptor implements Interceptor {
Charset charset = UTF8;
MediaType contentType = responseBody.contentType();
if (contentType != null) {
charset = contentType.charset(UTF8);
try {
charset = contentType.charset(UTF8);
} catch (UnsupportedCharsetException e) {
logger.log("");
logger.log("Couldn't decode the response body; charset is likely malformed.");
logger.log("<-- END HTTP");
return response;
}
}
if (contentLength != 0) {