Compare commits
2 Commits
0326bde209
...
1673f1680b
Author | SHA1 | Date | |
---|---|---|---|
1673f1680b | |||
04a82250d8 |
@ -0,0 +1,26 @@
|
|||||||
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintViolationException;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||||
|
|
||||||
|
public class ConstraintViolationExceptionCatcher implements ExceptionMapper<ConstraintViolationException> {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConstraintViolationExceptionCatcher.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response toResponse(final ConstraintViolationException exception) {
|
||||||
|
LOGGER.warn("Catch ConstraintViolationException: {}", exception.getLocalizedMessage());
|
||||||
|
final RestErrorResponse ret = build(exception);
|
||||||
|
LOGGER.error("Error OID={}", ret.oid);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity(ret).type(MediaType.APPLICATION_JSON).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private RestErrorResponse build(final ConstraintViolationException exception) {
|
||||||
|
return new RestErrorResponse(Response.Status.BAD_REQUEST, "Constraint Violation", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,6 +19,7 @@ public class GenericCatcher {
|
|||||||
rc.register(FailExceptionCatcher.class);
|
rc.register(FailExceptionCatcher.class);
|
||||||
// generic Exception catcher
|
// generic Exception catcher
|
||||||
rc.register(ExceptionCatcher.class);
|
rc.register(ExceptionCatcher.class);
|
||||||
|
rc.register(ConstraintViolationExceptionCatcher.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.kar.archidata.exception.DataAccessException;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import edu.umd.cs.findbugs.annotations.Nullable;
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import jakarta.ws.rs.InternalServerErrorException;
|
import jakarta.ws.rs.InternalServerErrorException;
|
||||||
|
|
||||||
@ -189,6 +190,7 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static <T, ID_TYPE> T get(final Class<T> clazz, final ID_TYPE id, final QueryOption... options)
|
public static <T, ID_TYPE> T get(final Class<T> clazz, final ID_TYPE id, final QueryOption... options)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
try (DBAccess db = DBAccess.createInterface()) {
|
try (DBAccess db = DBAccess.createInterface()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user