Sync: code local unifié

Synchronisation du code source local (fait foi).

Signed-off-by: lions dev Team
This commit is contained in:
dahoud
2026-03-15 16:25:40 +00:00
parent e82dc356f3
commit 75a19988b0
730 changed files with 53599 additions and 13145 deletions

View File

@@ -0,0 +1,103 @@
package dev.lions.unionflow.server.exception;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.Provider;
import org.jboss.logging.Logger;
import java.util.HashMap;
import java.util.Map;
/**
* Global Exception Mapper utilizing Quarkus ServerExceptionMapper for Resteasy
* Reactive.
*/
@Provider
@ApplicationScoped
public class GlobalExceptionMapper {
private static final Logger LOG = Logger.getLogger(GlobalExceptionMapper.class);
@ServerExceptionMapper
public Response mapRuntimeException(RuntimeException exception) {
LOG.warnf("Interception RuntimeException: %s - %s", exception.getClass().getName(), exception.getMessage());
if (exception instanceof IllegalArgumentException) {
return buildResponse(Response.Status.BAD_REQUEST, "Requête invalide", exception.getMessage());
}
if (exception instanceof IllegalStateException) {
return buildResponse(Response.Status.CONFLICT, "Conflit", exception.getMessage());
}
if (exception instanceof jakarta.ws.rs.NotFoundException) {
return buildResponse(Response.Status.NOT_FOUND, "Non trouvé", exception.getMessage());
}
if (exception instanceof jakarta.ws.rs.WebApplicationException) {
jakarta.ws.rs.WebApplicationException wae = (jakarta.ws.rs.WebApplicationException) exception;
Response originalResponse = wae.getResponse();
if (originalResponse.getStatus() >= 400 && originalResponse.getStatus() < 500) {
return buildResponse(Response.Status.fromStatusCode(originalResponse.getStatus()),
"Erreur Client",
wae.getMessage() != null && !wae.getMessage().isEmpty() ? wae.getMessage() : "Détails non disponibles");
}
}
LOG.error("Erreur non gérée", exception);
return buildResponse(Response.Status.INTERNAL_SERVER_ERROR, "Erreur interne", "Une erreur inattendue est survenue");
}
@ServerExceptionMapper({
JsonProcessingException.class,
JsonMappingException.class,
JsonParseException.class,
MismatchedInputException.class,
InvalidFormatException.class
})
public Response mapJsonException(Exception exception) {
LOG.warnf("Interception Erreur JSON: %s - %s", exception.getClass().getName(), exception.getMessage());
String friendlyMessage = "Erreur de format JSON";
if (exception instanceof InvalidFormatException) {
friendlyMessage = "Format de données invalide dans le JSON";
} else if (exception instanceof MismatchedInputException) {
friendlyMessage = "Format JSON invalide ou body manquant";
} else if (exception instanceof JsonMappingException) {
friendlyMessage = "Erreur de mapping JSON";
}
return buildResponse(Response.Status.BAD_REQUEST, "Requête invalide", friendlyMessage, exception.getMessage());
}
@ServerExceptionMapper
public Response mapBadRequestException(jakarta.ws.rs.BadRequestException exception) {
LOG.warnf("Interception BadRequestException: %s", exception.getMessage());
return buildResponse(Response.Status.BAD_REQUEST, "Requête mal formée", exception.getMessage());
}
private Response buildResponse(Response.Status status, String error, String message) {
return buildResponse(status, error, message, null);
}
private Response buildResponse(Response.Status status, String error, String message, String details) {
Map<String, Object> entity = new HashMap<>();
entity.put("error", error);
entity.put("message", message != null ? message : error);
// Toujours mettre des détails pour satisfaire les tests
entity.put("details", details != null ? details : (message != null ? message : error));
return Response.status(status)
.entity(entity)
.type(MediaType.APPLICATION_JSON)
.build();
}
}