Search in sources :

Example 11 with JsonApiExceptionMapper

use of io.crnk.core.engine.error.JsonApiExceptionMapper in project crnk-framework by crnk-project.

the class AbstractWrappedExceptionMapper method toErrorResponse.

@Override
public ErrorResponse toErrorResponse(E exception) {
    Throwable cause = exception.getCause();
    if (cause != null) {
        Optional<JsonApiExceptionMapper> mapper = context.getExceptionMapperRegistry().findMapperFor(cause.getClass());
        if (mapper.isPresent()) {
            return mapper.get().toErrorResponse(cause);
        }
    }
    LOGGER.error("failed to process request due to jpa exception", exception);
    // no mapper found, return default error
    int status = getStatus();
    ErrorData errorData = ErrorData.builder().setStatus(Integer.toString(status)).setTitle(exception.getMessage()).build();
    return ErrorResponse.builder().setSingleErrorData(errorData).setStatus(status).build();
}
Also used : JsonApiExceptionMapper(io.crnk.core.engine.error.JsonApiExceptionMapper) ErrorData(io.crnk.core.engine.document.ErrorData)

Aggregations

JsonApiExceptionMapper (io.crnk.core.engine.error.JsonApiExceptionMapper)11 Test (org.junit.Test)5 CrnkBoot (io.crnk.core.boot.CrnkBoot)3 ErrorData (io.crnk.core.engine.document.ErrorData)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Document (io.crnk.core.engine.document.Document)1 ErrorResponse (io.crnk.core.engine.error.ErrorResponse)1 ExceptionMapper (io.crnk.core.engine.error.ExceptionMapper)1 DocumentFilter (io.crnk.core.engine.filter.DocumentFilter)1 ExceptionMapperLookup (io.crnk.core.engine.internal.exception.ExceptionMapperLookup)1 ExceptionMapperRegistry (io.crnk.core.engine.internal.exception.ExceptionMapperRegistry)1 IllegalStateExceptionMapper (io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest.IllegalStateExceptionMapper)1 SomeIllegalStateExceptionMapper (io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest.SomeIllegalStateExceptionMapper)1 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 ServiceUrlProvider (io.crnk.core.engine.url.ServiceUrlProvider)1 InternalServerErrorException (io.crnk.core.exception.InternalServerErrorException)1 InvalidResourceException (io.crnk.core.exception.InvalidResourceException)1 Module (io.crnk.core.module.Module)1 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1