Class ResourceRegistryExceptionMapper
- All Implemented Interfaces:
jakarta.ws.rs.ext.ExceptionMapper<org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException>
ExceptionMapper that maps every ResourceRegistryException
thrown by the service into an HTTP error Response.
The mapped status code is derived from the exception's concrete subtype (e.g.
NotFoundException → 404, AlreadyPresentException/
ContextLifecycleException/SchemaViolationException → 409,
AvailableInAnotherContextException/ContextVisibilityException → 403),
defaulting to 400 Bad Request for any other subtype and 500 Internal Server
Error for a bare ResourceRegistryException. Every response body follows the unified
{"message": "..."} JSON error contract (see 07-api-foundations-and-roles.md).
The stack trace is always logged server-side. The wire body, however, differs by caller: a
request originating from one of this project's own Java client libraries (identified by
User-Agent, see JAVA_USER_AGENTS) receives the fully marshalled exception
(stack trace stripped) for backward-compatible client-side unmarshalling; any other caller
receives only the generic {"message": "..."} body, never the marshalled exception
shape.
- Author:
- Luca Frosini (ISTI - CNR)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjakarta.ws.rs.core.ResponsetoResponse(org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException exception) Maps the given exception to an HTTP errorResponse: selects the status code from the exception's concrete subtype (see the class Javadoc), always logs the stack trace, and builds a{"message": "..."}JSON body — or, for a caller identified as one of this project's own Java client libraries, the fully marshalled exception instead.
-
Constructor Details
-
ResourceRegistryExceptionMapper
public ResourceRegistryExceptionMapper()
-
-
Method Details
-
toResponse
public jakarta.ws.rs.core.Response toResponse(org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException exception) Maps the given exception to an HTTP errorResponse: selects the status code from the exception's concrete subtype (see the class Javadoc), always logs the stack trace, and builds a{"message": "..."}JSON body — or, for a caller identified as one of this project's own Java client libraries, the fully marshalled exception instead.- Specified by:
toResponsein interfacejakarta.ws.rs.ext.ExceptionMapper<org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException>- Parameters:
exception- the exception to map- Returns:
- the mapped HTTP error response
-