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

   ### What changes were proposed in this pull request?
   
   Follow-up to #12784. That PR registered `ParamExceptionMapper` (typed
   parameter conversion failures) and `NotFoundExceptionMapper` (unmatched
   routes), but those only cover two specific cases. Any other error
   JAX-RS/Jersey resolves itself before reaching a resource method — a wrong
   HTTP method (`NotAllowedException`, 405), an unacceptable `Accept` header
   (`NotAcceptableException`, 406), an unsupported `Content-Type`
   (`NotSupportedException`, 415) — was still unmapped and fell through to
   Jetty's default HTML error page, e.g. `POST /api/version`.
   
   This PR adds `WebApplicationExceptionMapper`, registered on the common
   `javax.ws.rs.WebApplicationException` base class as a catch-all. JAX-RS
   always selects the mapper for the nearest type in an exception's class
   hierarchy, so `ParamExceptionMapper` and `NotFoundExceptionMapper` still take
   precedence for the cases they already handle; this one only applies to the
   rest of the family.
   
   Confirmed no existing code throws a raw `WebApplicationException` subtype
   expecting to reach this mapper with custom headers/entity: the only two
   direct throws in `server/` (`NotSupportedException` in
   `MetadataObjectSecretOperations`/`MetadataObjectCredentialOperations`) are
   already caught by a local `try`/`catch` before ever reaching Jersey's
   provider chain.
   
   Fix: #12783
   
   ### Why are the changes needed?
   
   Stated more generally (per review discussion on #12784): any error Jersey
   resolves before reaching a resource method should return the same structured
   JSON body as the rest of the API, not just the two cases #12784 
special-cased.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A wrong HTTP method under `/api/*` (e.g. `POST /api/version`) now
   returns a structured JSON `ErrorResponse` — HTTP 405, type
   `UnsupportedOperationException` — instead of Jetty's default HTML error
   page. The same applies to 406/415-class failures. No other endpoint's
   behavior changes.
   
   ### How was this patch tested?
   
   - Added `TestWebApplicationExceptionMapper` (unit test) covering
     `NotAllowedException` (405), `NotSupportedException` (415), and
     `NotAcceptableException` (406).
   - Extended `JsonErrorHandlerIT` with a `POST /api/version` case; all 4 cases
     pass both with the Web UI disabled and enabled.
   - Ran the full `server` and `server-common` unit test suites; no
     regressions.
   


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