epugh commented on code in PR #2621:
URL: https://github.com/apache/solr/pull/2621#discussion_r1719667781


##########
solr/core/src/java/org/apache/solr/handler/IndexFetcher.java:
##########
@@ -1988,16 +1989,38 @@ private FastInputStream getStream() throws IOException {
         req.setBasePath(leaderBaseUrl);
         if (useExternalCompression) req.addHeader("Accept-Encoding", "gzip");
         response = solrClient.request(req, leaderCoreName);
+        final var responseStatus = (Integer) response.get("responseStatus");
         is = (InputStream) response.get("stream");
+
+        if (responseStatus != 200) {
+          final var errorMsg =
+              String.format(
+                  Locale.ROOT,
+                  "Unexpected status code [%d] when downloading file [%s].",
+                  responseStatus,
+                  fileName);
+          closeStreamAndThrowIOE(is, errorMsg, Optional.empty());
+        }
+
         if (useInternalCompression) {
           is = new InflaterInputStream(is);
         }
         return new FastInputStream(is);
       } catch (Exception e) {
-        // close stream on error
-        IOUtils.closeQuietly(is);
-        throw new IOException("Could not download file '" + fileName + "'", e);
+        closeStreamAndThrowIOE(is, "Could not download file '" + fileName + 
"'", Optional.of(e));
+      }
+
+      // Unreachable b/c closeStreamAndThrowIOE will always throw
+      return null;
+    }
+
+    private void closeStreamAndThrowIOE(
+        InputStream is, String exceptionMessage, Optional<Exception> e) throws 
IOException {

Review Comment:
   We really need more coding style guides and ideally lint checking tools for 
things like Optional.   Or in 12 months, we'll have this same conversation, but 
with someone new ;-(.    



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to