[DOC] add comment
This commit is contained in:
parent
1e05e8361a
commit
cef06889ee
@ -8,9 +8,19 @@ import jakarta.ws.rs.core.MediaType;
|
|||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class catches InputException and maps it to a HTTP response.
|
||||||
|
*/
|
||||||
public class InputExceptionCatcher implements ExceptionMapper<InputException> {
|
public class InputExceptionCatcher implements ExceptionMapper<InputException> {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(InputExceptionCatcher.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(InputExceptionCatcher.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called when an InputException is thrown.
|
||||||
|
* It logs the exception and builds a response with the error details.
|
||||||
|
*
|
||||||
|
* @param exception the InputException that was thrown
|
||||||
|
* @return a Response object containing the error details
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Response toResponse(final InputException exception) {
|
public Response toResponse(final InputException exception) {
|
||||||
LOGGER.warn("Catch InputException:");
|
LOGGER.warn("Catch InputException:");
|
||||||
@ -21,6 +31,12 @@ public class InputExceptionCatcher implements ExceptionMapper<InputException> {
|
|||||||
return Response.status(exception.status).entity(ret).type(MediaType.APPLICATION_JSON).build();
|
return Response.status(exception.status).entity(ret).type(MediaType.APPLICATION_JSON).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method builds a RestErrorResponse object from the InputException.
|
||||||
|
*
|
||||||
|
* @param exception the InputException that was thrown
|
||||||
|
* @return a RestErrorResponse object containing the error details
|
||||||
|
*/
|
||||||
private RestErrorResponse build(final InputException exception) {
|
private RestErrorResponse build(final InputException exception) {
|
||||||
return new RestErrorResponse(exception.status, "Error on input='" + exception.missingVariable + "'",
|
return new RestErrorResponse(exception.status, "Error on input='" + exception.missingVariable + "'",
|
||||||
exception.getMessage());
|
exception.getMessage());
|
||||||
|
@ -12,6 +12,13 @@ import jakarta.ws.rs.ext.ExceptionMapper;
|
|||||||
public class JacksonExceptionCatcher implements ExceptionMapper<JacksonException> {
|
public class JacksonExceptionCatcher implements ExceptionMapper<JacksonException> {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(JacksonExceptionCatcher.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(JacksonExceptionCatcher.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called when a JacksonException is thrown.
|
||||||
|
* It logs the exception, builds a response with the error details, and returns it.
|
||||||
|
*
|
||||||
|
* @param exception the JacksonException that was thrown
|
||||||
|
* @return a Response object containing the error details
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Response toResponse(final JacksonException exception) {
|
public Response toResponse(final JacksonException exception) {
|
||||||
LOGGER.warn("Catch exception Input data parsing:");
|
LOGGER.warn("Catch exception Input data parsing:");
|
||||||
@ -22,6 +29,12 @@ public class JacksonExceptionCatcher implements ExceptionMapper<JacksonException
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a RestErrorResponse object from the given exception.
|
||||||
|
*
|
||||||
|
* @param exception the Exception that was thrown
|
||||||
|
* @return a RestErrorResponse object containing the error details
|
||||||
|
*/
|
||||||
private RestErrorResponse build(final Exception exception) {
|
private RestErrorResponse build(final Exception exception) {
|
||||||
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Catch JSON Exception",
|
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Catch JSON Exception",
|
||||||
exception.getMessage());
|
exception.getMessage());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user