jerryshao opened a new pull request, #12784:
URL: https://github.com/apache/gravitino/pull/12784
### What changes were proposed in this pull request?
`{version}` on the model version endpoints (and any other typed `@PathParam`
on
the metadata API) is matched and converted by Jersey before any resource
method or registered `ExceptionMapper` runs. When a non-numeric value is
supplied, that conversion fails and Jersey's `ServletContainer` calls
`HttpServletResponse#sendError` directly, which falls through to Jetty's own
default `ErrorHandler` — producing an HTML error page instead of a Gravitino
`ErrorResponse`.
This PR adds a `JsonErrorHandler` (a Jetty `ErrorHandler`) that writes the
same
structured JSON `ErrorResponse` used by every other error on the API for any
request under `/api/*`, and wires it in via a new `createErrorHandler()`
extension point on `JettyServer` (mirroring the existing
`createAuthenticationFilter()` pattern). Paths outside `/api/*` — the Web UI,
`/configs`, `/metrics`, `/health/*` — are unaffected and keep Jetty's normal
HTML handling.
### Why are the changes needed?
Every other error on the metadata API returns a structured body carrying a
Gravitino error code and type. A caller that receives HTML on one input shape
and JSON on every other has to special-case the parser, and the response
identifies the servlet container and its version to anyone who sends a bad
value.
Fix: #12783
### Does this PR introduce _any_ user-facing change?
Yes. A malformed typed path parameter under `/api/*` (e.g.
`GET /api/metalakes/{ml}/catalogs/{c}/schemas/{s}/models/{m}/versions/abc`)
now returns a structured JSON `ErrorResponse` (HTTP 404, type
`NotFoundException`) instead of Jetty's default HTML error page. No other
endpoint's behavior changes.
### How was this patch tested?
- Added `TestJsonErrorHandler` (unit test) covering the path-prefix decision
and the status-code-to-`ErrorResponse` mapping for 400/401/403/404/405/500.
- Added `JsonErrorHandlerIT` (integration test against a real running
server) covering a malformed model version, a malformed model version URI,
and an unmatched `/api/*` route, asserting a JSON `Content-Type` and a
parseable `ErrorResponse` body.
- Ran the full `server` and `server-common` unit test suites; no regressions
(one pre-existing, unrelated TLS-handshake flake in
`TestHttpsServerAuthentication` reproduces identically without this
change).
--
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]