Skip to content
Snippets Groups Projects
Commit 227d32d1 authored by Greg DiCristofaro's avatar Greg DiCristofaro
Browse files

better error message

parent cfb619aa
No related branches found
No related tags found
No related merge requests found
...@@ -158,16 +158,23 @@ public <O> O doPost(String urlPath, Map<String, String> urlReqParams, Object jso ...@@ -158,16 +158,23 @@ public <O> O doPost(String urlPath, Map<String, String> urlReqParams, Object jso
// Parse Response // Parse Response
if (classType != null) { if (classType != null) {
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
String entityStr = EntityUtils.toString(entity); if (entity != null) {
O respObj = mapper.readValue(entityStr, classType); String entityStr = EntityUtils.toString(entity);
return respObj; if (StringUtils.isNotBlank(entityStr)) {
} else { O respObj = mapper.readValue(entityStr, classType);
return null; return respObj;
}
}
} }
return null;
} else { } else {
LOGGER.log(Level.WARNING, "Response Received. - Status Error {}", response.getStatusLine()); LOGGER.log(Level.WARNING, "Response Received. - Status Error {}", response.getStatusLine());
handleNonOKResponse(response, ""); handleNonOKResponse(response, "");
} }
// transform all non-CTCloudException's into a CTCloudException
} catch (CTCloudException ex) {
throw ex;
} catch (Exception ex) { } catch (Exception ex) {
LOGGER.log(Level.WARNING, "Error when parsing response from CyberTriage Cloud", ex); LOGGER.log(Level.WARNING, "Error when parsing response from CyberTriage Cloud", ex);
throw new CTCloudException(CTCloudException.parseUnknownException(ex), ex); throw new CTCloudException(CTCloudException.parseUnknownException(ex), ex);
...@@ -191,7 +198,7 @@ public void doFileUploadPut(FileUploadRequest fileUploadRequest) throws CTCloudE ...@@ -191,7 +198,7 @@ public void doFileUploadPut(FileUploadRequest fileUploadRequest) throws CTCloudE
if (fileUploadRequest == null) { if (fileUploadRequest == null) {
throw new CTCloudException(ErrorCode.BAD_REQUEST, new IllegalArgumentException("fileUploadRequest cannot be null")); throw new CTCloudException(ErrorCode.BAD_REQUEST, new IllegalArgumentException("fileUploadRequest cannot be null"));
} }
String fullUrlPath = fileUploadRequest.getFullUrlPath(); String fullUrlPath = fileUploadRequest.getFullUrlPath();
String fileName = fileUploadRequest.getFileName(); String fileName = fileUploadRequest.getFileName();
InputStream fileInputStream = fileUploadRequest.getFileInputStream(); InputStream fileInputStream = fileUploadRequest.getFileInputStream();
...@@ -200,7 +207,7 @@ public void doFileUploadPut(FileUploadRequest fileUploadRequest) throws CTCloudE ...@@ -200,7 +207,7 @@ public void doFileUploadPut(FileUploadRequest fileUploadRequest) throws CTCloudE
if (StringUtils.isBlank(fullUrlPath) || fileInputStream == null || contentLength == null || contentLength <= 0) { if (StringUtils.isBlank(fullUrlPath) || fileInputStream == null || contentLength == null || contentLength <= 0) {
throw new CTCloudException(ErrorCode.BAD_REQUEST, new IllegalArgumentException("fullUrlPath, fileInputStream, contentLength must not be empty, null or less than 0")); throw new CTCloudException(ErrorCode.BAD_REQUEST, new IllegalArgumentException("fullUrlPath, fileInputStream, contentLength must not be empty, null or less than 0"));
} }
URI putUri; URI putUri;
try { try {
putUri = new URI(fullUrlPath); putUri = new URI(fullUrlPath);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment