All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.qe.database.oracle.ApplicationExceptionMapper Maven / Gradle / Ivy

package io.quarkus.qe.database.oracle;

import jakarta.ws.rs.WebApplicationException;
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 com.fasterxml.jackson.databind.ObjectMapper;

@Provider
public class ApplicationExceptionMapper implements ExceptionMapper {
    @Override
    public Response toResponse(Exception exception) {
        int code = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
        if (exception instanceof WebApplicationException) {
            code = ((WebApplicationException) exception).getResponse().getStatus();
        }

        return Response.status(code)
                .type(MediaType.APPLICATION_JSON)
                .entity(new ObjectMapper().createObjectNode()
                        .put("code", code)
                        .put("error", exception.getMessage())
                        .toString())
                .build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy