Copilot commented on code in PR #9949:
URL: https://github.com/apache/ozone/pull/9949#discussion_r3115470246


##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/exception/TestOS3Exceptions.java:
##########
@@ -48,9 +49,19 @@ public void testOS3Exceptions() {
     assertEquals(expected, val);
   }
 
+  /**
+   * AWS S3 returns HTTP 400 Bad Request for ExpiredToken (not 403).
+   */
+  @Test
+  public void testExpiredTokenUsesBadRequestHttpStatus() {
+    assertEquals(HTTP_BAD_REQUEST, S3ErrorTable.EXPIRED_TOKEN.getHttpCode());
+    final OS3Exception fromTable = 
S3ErrorTable.newError(S3ErrorTable.EXPIRED_TOKEN, "resource");
+    assertEquals(HTTP_BAD_REQUEST, fromTable.getHttpCode());
+  }
+
   @Test
   public void testOS3ExceptionWithToken0() {
-    OS3Exception ex = new OS3Exception("ExpiredToken", "The provided token has 
expired.", 403);
+    OS3Exception ex = new OS3Exception("ExpiredToken", "The provided token has 
expired.", 400);

Review Comment:
   This test hard-codes HTTP status 400 even though the file already imports 
HTTP_BAD_REQUEST. Using the constant here would avoid a magic number and keep 
the test resilient if the status code mapping changes again.
   ```suggestion
       OS3Exception ex = new OS3Exception("ExpiredToken", "The provided token 
has expired.",
           HTTP_BAD_REQUEST);
   ```



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java:
##########
@@ -379,24 +379,33 @@ private Iterator<? extends OzoneBucket> iterateBuckets(
       OzoneVolume volume = getVolume();
       ownerSetter.accept(volume);
       return query.apply(volume);
-    } catch (OMException e) {
-      if (e.getResult() == ResultCodes.VOLUME_NOT_FOUND) {
-        return Collections.emptyIterator();
-      } else  if (e.getResult() == ResultCodes.PERMISSION_DENIED) {
-        throw newError(S3ErrorTable.ACCESS_DENIED,
-            "listBuckets", e);
-      } else if (isExpiredToken(e)) {
-        throw newError(S3ErrorTable.EXPIRED_TOKEN, s3Auth.getAccessID(), e);
-      } else if (e.getResult() == ResultCodes.INVALID_TOKEN) {
-        throw newError(S3ErrorTable.ACCESS_DENIED,
-            s3Auth.getAccessID(), e);
-      } else if (e.getResult() == ResultCodes.TIMEOUT ||
-          e.getResult() == ResultCodes.INTERNAL_ERROR) {
-        throw newError(S3ErrorTable.INTERNAL_ERROR,
-            "listBuckets", e);
-      } else {
-        throw e;
+    } catch (RuntimeException e) {
+      if (e.getCause() instanceof OMException) {
+        return handleOMException((OMException) e.getCause());
       }
+      throw e;
+    } catch (OMException e) {
+      return handleOMException(e);
+    }
+  }
+
+  private Iterator<OzoneBucket> handleOMException(OMException e) throws 
OMException {

Review Comment:
   `handleOMException` returns `Iterator<OzoneBucket>` while the calling code 
uses `Iterator<? extends OzoneBucket>`. Returning the wildcard type here would 
better match the surrounding API and avoid unnecessarily narrowing the type 
(even though it currently only returns an empty iterator).
   ```suggestion
     private Iterator<? extends OzoneBucket> handleOMException(OMException e) 
throws OMException {
   ```



-- 
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