From 227d32d1c01b81ea34cc01c3f09de51f94c4de40 Mon Sep 17 00:00:00 2001
From: Greg DiCristofaro <gregd@basistech.com>
Date: Fri, 25 Aug 2023 07:56:29 -0400
Subject: [PATCH] better error message

---
 .../autopsy/ctapi/CTCloudHttpClient.java      | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/ctapi/CTCloudHttpClient.java b/Core/src/com/basistech/df/cybertriage/autopsy/ctapi/CTCloudHttpClient.java
index 0a7c69cdee..cf93d58307 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/ctapi/CTCloudHttpClient.java
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/ctapi/CTCloudHttpClient.java
@@ -158,16 +158,23 @@ public <O> O doPost(String urlPath, Map<String, String> urlReqParams, Object jso
                         // Parse Response
                         if (classType != null) {
                             HttpEntity entity = response.getEntity();
-                            String entityStr = EntityUtils.toString(entity);
-                            O respObj = mapper.readValue(entityStr, classType);
-                            return respObj;
-                        } else {
-                            return null;
+                            if (entity != null) {
+                                String entityStr = EntityUtils.toString(entity);
+                                if (StringUtils.isNotBlank(entityStr)) {
+                                    O respObj = mapper.readValue(entityStr, classType);
+                                    return respObj;
+                                }
+                            }
                         }
+
+                        return null;
                     } else {
                         LOGGER.log(Level.WARNING, "Response Received. - Status Error {}", response.getStatusLine());
                         handleNonOKResponse(response, "");
                     }
+                    // transform all non-CTCloudException's into a CTCloudException
+                } catch (CTCloudException ex) {
+                    throw ex;
                 } catch (Exception ex) {
                     LOGGER.log(Level.WARNING, "Error when parsing response from CyberTriage Cloud", ex);
                     throw new CTCloudException(CTCloudException.parseUnknownException(ex), ex);
@@ -191,7 +198,7 @@ public void doFileUploadPut(FileUploadRequest fileUploadRequest) throws CTCloudE
         if (fileUploadRequest == null) {
             throw new CTCloudException(ErrorCode.BAD_REQUEST, new IllegalArgumentException("fileUploadRequest cannot be null"));
         }
-                
+
         String fullUrlPath = fileUploadRequest.getFullUrlPath();
         String fileName = fileUploadRequest.getFileName();
         InputStream fileInputStream = fileUploadRequest.getFileInputStream();
@@ -200,7 +207,7 @@ public void doFileUploadPut(FileUploadRequest fileUploadRequest) throws CTCloudE
         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"));
         }
-        
+
         URI putUri;
         try {
             putUri = new URI(fullUrlPath);
-- 
GitLab