Skip to content

Commit

Permalink
#14 Handle JsonSyntaxException in BoschHttpClient.sendRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Oeing <[email protected]>
Signed-off-by: Gerd Zanker <[email protected]>
  • Loading branch information
coeing authored and GerdZanker committed Jan 7, 2021
1 parent bfabace commit 4c9df55
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

/**
* HTTP client using own context with private & Bosch Certs
Expand Down Expand Up @@ -175,13 +176,17 @@ public <TContent> TContent sendRequest(Request request, Class<TContent> response
logger.debug("BoschHttpClient: response complete: {} - return code: {}", contentResponse.getContentAsString(),
contentResponse.getStatus());

@Nullable
TContent content = gson.fromJson(contentResponse.getContentAsString(), responseContentClass);
if (content == null) {
throw new ExecutionException(String.format("Received invalid content in response, expected type %s",
responseContentClass.getName()), null);
try {
@Nullable
TContent content = gson.fromJson(contentResponse.getContentAsString(), responseContentClass);
if (content == null) {
throw new ExecutionException(String.format("Received no content in response, expected type %s",
responseContentClass.getName()), null);
}
return content;
} catch (JsonSyntaxException e) {
throw new ExecutionException(String.format("Received invalid content in response, expected type %s: %s",
responseContentClass.getName(), e.getMessage()), null);
}

return content;
}
}

0 comments on commit 4c9df55

Please sign in to comment.