[DEV] Correct all catcher to be named normalized
This commit is contained in:
parent
7b72b08fc0
commit
91849094cd
@ -21,8 +21,8 @@ public class ExceptionCatcher implements ExceptionMapper<Exception> {
|
||||
}
|
||||
|
||||
private RestErrorResponse build(final Exception exception) {
|
||||
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Catch Unknown Exception",
|
||||
exception.getMessage());
|
||||
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR,
|
||||
"Catch Unknown Exception: " + exception.getClass().getCanonicalName(), exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
24
src/org/kar/archidata/catcher/GenericCatcher.java
Normal file
24
src/org/kar/archidata/catcher/GenericCatcher.java
Normal file
@ -0,0 +1,24 @@
|
||||
package org.kar.archidata.catcher;
|
||||
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
public class GenericCatcher {
|
||||
|
||||
/**
|
||||
* Add All the the generic catcher to standardize returns.
|
||||
* @param rc Resource exception model.
|
||||
*/
|
||||
public static void addAll(final ResourceConfig rc) {
|
||||
// Generic Json parsing error
|
||||
rc.register(JacksonExceptionCatcher.class);
|
||||
// Catch jakarta generic errors
|
||||
rc.register(WebApplicationExceptionCatcher.class);
|
||||
// Archidata exceptions
|
||||
rc.register(InputExceptionCatcher.class);
|
||||
rc.register(SystemExceptionCatcher.class);
|
||||
rc.register(FailExceptionCatcher.class);
|
||||
// generic Exception catcher
|
||||
rc.register(ExceptionCatcher.class);
|
||||
}
|
||||
|
||||
}
|
@ -3,17 +3,17 @@ package org.kar.archidata.catcher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||
|
||||
public class JacksonCatcher implements ExceptionMapper<JsonProcessingException> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JacksonCatcher.class);
|
||||
public class JacksonExceptionCatcher implements ExceptionMapper<JacksonException> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JacksonExceptionCatcher.class);
|
||||
|
||||
@Override
|
||||
public Response toResponse(final JsonProcessingException exception) {
|
||||
public Response toResponse(final JacksonException exception) {
|
||||
LOGGER.warn("Catch exception Input data parsing:");
|
||||
final RestErrorResponse ret = build(exception);
|
||||
LOGGER.error("Error UUID={}", ret.uuid);
|
@ -3,23 +3,23 @@ package org.kar.archidata.catcher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.ClientErrorException;
|
||||
import jakarta.ws.rs.WebApplicationException;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||
|
||||
public class FailException404API implements ExceptionMapper<ClientErrorException> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FailException404API.class);
|
||||
public class WebApplicationExceptionCatcher implements ExceptionMapper<WebApplicationException> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WebApplicationExceptionCatcher.class);
|
||||
|
||||
@Override
|
||||
public Response toResponse(final ClientErrorException exception) {
|
||||
public Response toResponse(final WebApplicationException exception) {
|
||||
final RestErrorResponse ret = build(exception);
|
||||
LOGGER.error("Error UUID={}", ret.uuid);
|
||||
return Response.status(exception.getResponse().getStatusInfo().toEnum()).entity(ret)
|
||||
.type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
private RestErrorResponse build(final ClientErrorException exception) {
|
||||
private RestErrorResponse build(final WebApplicationException exception) {
|
||||
return new RestErrorResponse(exception.getResponse().getStatusInfo().toEnum(), "Catch system exception",
|
||||
exception.getMessage());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user