use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class ErrorDataDeserializer method deserialize.
@Override
public ErrorData deserialize(JsonParser jp, DeserializationContext context) throws IOException {
JsonNode errorNode = jp.readValueAsTree();
String id = SerializerUtil.readStringIfExists(ErrorDataSerializer.ID, errorNode);
String aboutLink = readAboutLink(errorNode);
String status = SerializerUtil.readStringIfExists(ErrorDataSerializer.STATUS, errorNode);
String code = SerializerUtil.readStringIfExists(ErrorDataSerializer.CODE, errorNode);
String title = SerializerUtil.readStringIfExists(ErrorDataSerializer.TITLE, errorNode);
String detail = SerializerUtil.readStringIfExists(ErrorDataSerializer.DETAIL, errorNode);
Map<String, Object> meta = readMeta(errorNode, jp);
String sourcePointer = readSourcePointer(errorNode);
String sourceParameter = readSourceParameter(errorNode);
return new ErrorData(id, aboutLink, status, code, title, detail, sourcePointer, sourceParameter, meta);
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class CustomExceptionMapper method toErrorResponse.
@Override
public ErrorResponse toErrorResponse(CustomException e) {
ErrorDataBuilder builder = ErrorData.builder();
builder.setStatus(String.valueOf(CUSTOM_ERROR_STATUS_CODE));
builder.setTitle(e.getMessage());
ErrorData error = builder.build();
List<ErrorData> errors = Arrays.asList(error);
return ErrorResponse.builder().setStatus(CUSTOM_ERROR_STATUS_CODE).setErrorData(errors).build();
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class ClientStubBaseTest method checkBodyWithErrors.
@Test
public void checkBodyWithErrors() throws IOException {
Document document = new Document();
ErrorData errorData = new ErrorDataBuilder().setCode("404").setDetail("detail").build();
document.setErrors(Arrays.asList(errorData));
String body = client.getObjectMapper().writeValueAsString(document);
HttpAdapterResponse response = Mockito.mock(HttpAdapterResponse.class);
Mockito.when(response.body()).thenReturn(body);
Mockito.when(response.getResponseHeader(HttpHeaders.HTTP_CONTENT_TYPE)).thenReturn(HttpHeaders.JSONAPI_CONTENT_TYPE);
Mockito.when(response.code()).thenReturn(404);
RuntimeException exception = stub.handleError(response);
Assert.assertTrue(exception instanceof ResourceNotFoundException);
Assert.assertEquals("detail", exception.getMessage());
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class ExceptionMapperHelper method createErrorMessage.
public static String createErrorMessage(ErrorResponse errorResponse) {
Iterator<ErrorData> errors = errorResponse.getErrors().iterator();
String message = null;
if (errors.hasNext()) {
ErrorData data = errors.next();
message = data.getCode();
}
return message;
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class ExceptionMapperHelper method toErrorResponse.
public static ErrorResponse toErrorResponse(Throwable exception, int statusCode, String metaTypeValue) {
List<ErrorData> errors = new ArrayList<>();
ErrorDataBuilder builder = ErrorData.builder();
builder = builder.addMetaField(ExceptionMapperHelper.META_TYPE_KEY, metaTypeValue);
builder = builder.setStatus(String.valueOf(statusCode));
builder = builder.setCode(exception.getMessage());
builder = builder.setTitle(exception.getLocalizedMessage());
ErrorData error = builder.build();
errors.add(error);
return ErrorResponse.builder().setStatus(statusCode).setErrorData(errors).build();
}
Aggregations