All checks were successful
Build, test and publish / verify (push) Successful in 4m43s
25 lines
857 B
Java
25 lines
857 B
Java
package nl.agilecc.agiledancers.rest;
|
|
|
|
import jakarta.ws.rs.core.MediaType;
|
|
import jakarta.ws.rs.core.Response;
|
|
import jakarta.ws.rs.ext.ExceptionMapper;
|
|
import jakarta.ws.rs.ext.Provider;
|
|
import nl.agilecc.agiledancers.rest.apimodel.ErrorView;
|
|
import nl.agilecc.agiledancers.service.ManagementException;
|
|
|
|
@Provider
|
|
public class ManagementExceptionMapper implements ExceptionMapper<ManagementException> {
|
|
@Override
|
|
public Response toResponse(final ManagementException exception) {
|
|
final int status = switch (exception.getKind()) {
|
|
case NOT_FOUND -> 404;
|
|
case INVALID_INPUT -> 400;
|
|
case CONFLICT -> 409;
|
|
};
|
|
return Response.status(status)
|
|
.type(MediaType.APPLICATION_JSON_TYPE)
|
|
.entity(new ErrorView(exception.getMessage()))
|
|
.build();
|
|
}
|
|
}
|