Skip to content

Commit

Permalink
added check for null api InputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Dec 19, 2022
1 parent ad3ec91 commit 99180fa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/mangopay/core/RestTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ private <T extends Dto, U extends Dto> T doRequest(Class<T> classOfT, String ide
is = connection.getInputStream();
}

checkApiConnection(is);

StringBuffer resp;
try (BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
String line;
Expand Down Expand Up @@ -597,6 +599,8 @@ private <T extends Dto> List<T> doRequestList(Class<T[]> classOfT, Class<T> clas
is = connection.getInputStream();
}

checkApiConnection(is);

StringBuffer resp;
try (BufferedReader rd = new BufferedReader(new InputStreamReader(is))) {
String line;
Expand Down Expand Up @@ -679,6 +683,17 @@ private Map<String, String> getHttpHeaders(String restUrl) throws Exception {
return httpHeaders;
}

private void checkApiConnection(InputStream is) throws ResponseException {
if (is == null) {
ResponseException responseException = new ResponseException("Connection to Mangopay API failed");
responseException.setResponseHttpCode(500);
responseException.setResponseHttpDescription("Internal Server Error");
responseException.setApiMessage("Connection to Mangopay API failed");

throw responseException;
}
}

/**
* Checks the HTTP response code and if it's neither 200 nor 204 throws a ResponseException.
*
Expand Down

0 comments on commit 99180fa

Please sign in to comment.