SARAMALI15792 opened a new pull request, #10634:
URL: https://github.com/apache/gravitino/pull/10634

   ## Summary
   Fixes #10626 - Invalid metadata object type now returns HTTP 400 Bad Request 
with a clear error message instead of HTTP 500 Internal Server Error.
   
   ## Root Cause
   When a REST API request includes an unsupported `metadataObjectType` path 
parameter:
   1. `ParameterUtil.extractNameIdentifierFromParameters()` calls 
`MetadataObject.Type.valueOf()`
   2. `valueOf()` throws `IllegalArgumentException` for invalid enum values
   3. Exception propagates to authorization interceptor's generic exception 
handler
   4. Generic handler treats all exceptions as internal errors (HTTP 500)
   
   **File**: 
`server/src/main/java/org/apache/gravitino/server/web/filter/ParameterUtil.java:86`
   
   ## Changes
   - Added try-catch around `MetadataObject.Type.valueOf()` in 
`ParameterUtil.java`
   - Throw descriptive `IllegalArgumentException` with list of valid types
   - Added regression test in `TestMetadataObjectTagOperations.java`
   
   ## Why This Is Safe
   - Only affects error handling path (invalid user input)
   - `IllegalArgumentException` already handled correctly by 
`ExceptionHandlers.java` (returns 400)
   - No changes to successful request flow
   - Follows existing error handling patterns in the codebase
   
   ## Testing
   
   **Before fix:**
   ```bash
   curl -X GET 
"http://localhost:8090/api/metalakes/test/objects/INVALID_TYPE/catalog.schema.table/tags";
   # Returns: 500 Internal Server Error
   # Message: "Authorization failed due to system internal error"
   ```
   
   **After fix:**
   ```bash
   curl -X GET 
"http://localhost:8090/api/metalakes/test/objects/INVALID_TYPE/catalog.schema.table/tags";
   # Returns: 400 Bad Request
   # Message: "Invalid metadata object type: INVALID_TYPE. Valid types are: 
METALAKE, CATALOG, SCHEMA, FILESET, TABLE, VIEW, TOPIC, COLUMN, ROLE, MODEL, 
TAG, POLICY, JOB, JOB_TEMPLATE"
   ```
   
   **Regression test added:**
   - Tests invalid metadata object type returns 400
   - Verifies error message contains invalid type and helpful guidance
   - Tests multiple invalid type scenarios
   
   ## Related
   - Investigation posted to issue: 
https://github.com/apache/gravitino/issues/10626#issuecomment-4168253810
   - Similar fix: #9271 (improved error responses in authorization flow)


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

Reply via email to