Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into dep/dependency_upgrade_staging
Browse files Browse the repository at this point in the history
  • Loading branch information
shawn-sher committed Jun 13, 2022
2 parents 4399462 + 5219ea9 commit 6dfafcf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLException;
import okhttp3.*;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -177,8 +183,10 @@ protected ApiException toApiException(IOException e) {
* @return Deserialized object from the response body
*/
protected <M> M parseResponseBody(final Response response, final Class<M> responseClass) {
final ResponseBody body = response.body();
try {
return objectMapper.readValue(response.body().string(), responseClass);
final String responseBodyString = body == null ? "" : body.string();
return objectMapper.readValue(responseBodyString, responseClass);
} catch (IOException e) {
throw ApiException.newBuilder()
.withApiErrors(DefaultApiError.SERVICE_UNAVAILABLE)
Expand Down
2 changes: 1 addition & 1 deletion cerberus-web/src/main/java/com/nike/cerberus/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void main(String... args) {
new SpringApplicationBuilder()
.properties(
Map.of(
"spring.config.additional-location", "${user.home}/.cerberus/",
"spring.config.additional-location", "optional:${user.home}/.cerberus/",
"spring.application.name", "cerberus",
"spring.config.name", "cerberus",
"spring.profiles.active", "${cerberus.environment:local}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ public <M> M execute(

throw builder.withExceptionMessage(msg).build();
} else if (response.code() >= 500) {
final ResponseBody body = response.body();
final String bodyString = body == null ? "" : body.string();
final String msg =
String.format(
"Something is wrong with AWS, error message: %s", response.body().string());
String.format("Something is wrong with AWS, error message: %s", bodyString);

throw ApiException.newBuilder()
.withApiErrors(
Expand Down Expand Up @@ -161,8 +162,11 @@ protected ApiException toApiException(IOException e) {
* @return Deserialized object from the response body
*/
protected <M> M parseResponseBody(final Response response, final Class<M> responseClass) {

final ResponseBody body = response.body();
try {
return objectMapper.readValue(response.body().string(), responseClass);
final String responseBodyString = body == null ? "" : body.string();
return objectMapper.readValue(responseBodyString, responseClass);
} catch (IOException e) {
String msg = "Error parsing the response body from AWS STS.";
throw ApiException.newBuilder()
Expand Down

0 comments on commit 6dfafcf

Please sign in to comment.