feat: better error message
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package fr.titionfire.ffsaf.rest.exception;
|
||||
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
public class DBadRequestException extends DetailException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 7518556311032332135L;
|
||||
|
||||
public DBadRequestException(String message) {
|
||||
super(Response.Status.BAD_REQUEST, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package fr.titionfire.ffsaf.rest.exception;
|
||||
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
public class DForbiddenException extends DetailException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 8408920537659758038L;
|
||||
|
||||
public DForbiddenException() {
|
||||
this("Accès a la ressource interdite");
|
||||
}
|
||||
|
||||
public DForbiddenException(String message) {
|
||||
super(Response.Status.FORBIDDEN, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package fr.titionfire.ffsaf.rest.exception;
|
||||
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
public class DInternalError extends DetailException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = -3635595157694180842L;
|
||||
|
||||
public DInternalError(String message) {
|
||||
super(Response.Status.INTERNAL_SERVER_ERROR, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package fr.titionfire.ffsaf.rest.exception;
|
||||
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
public class DNotFoundException extends DetailException{
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = -5193524134675732376L;
|
||||
|
||||
public DNotFoundException(String message) {
|
||||
super(Response.Status.NOT_FOUND, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package fr.titionfire.ffsaf.rest.exception;
|
||||
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@Getter
|
||||
public class DetailException extends Exception {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 5349921926328753676L;
|
||||
|
||||
private final Response.Status status;
|
||||
|
||||
public DetailException(Response.Status status, String message) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package fr.titionfire.ffsaf.rest.exception;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
public class DetailExceptionMapper implements ExceptionMapper<DetailException> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(DetailException e) {
|
||||
return Response.status(e.getStatus())
|
||||
.entity(e.getMessage())
|
||||
.type(MediaType.TEXT_PLAIN_TYPE)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package fr.titionfire.ffsaf.rest.exception;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.KeycloakException;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
public class KeycloakExceptionMapper implements ExceptionMapper<KeycloakException> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(KeycloakException e) {
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||
.entity("Erreur du gestionnaire d'identité: " + e.getMessage())
|
||||
.type(MediaType.TEXT_PLAIN_TYPE)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user