Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing meaningful information into an exception when deserialization… #141

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/java/com/onfido/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package com.onfido;

import com.google.gson.JsonParseException;
import okhttp3.*;
import okhttp3.internal.http.HttpMethod;
import okhttp3.internal.tls.OkHostnameVerifier;
Expand Down Expand Up @@ -952,7 +953,15 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
contentType = "application/json";
}
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody, returnType);
try {
return JSON.deserialize(respBody, returnType);
} catch (JsonParseException e) {
throw new ApiException(
"Unable to deserialize a response body \"" + respBody + "\" into type: " + returnType,
response.code(),
response.headers().toMultimap(),
respBody);
}
} else if (returnType.equals(String.class)) {
// Expecting string, return the raw response body.
return (T) respBody;
Expand Down