use of org.talend.daikon.exception.error.ErrorCode in project data-prep by Talend.
the class CommonAPI method writeErrorsFromEnum.
/**
* Write the given error codes to the generator.
*
* @param generator the json generator to use.
* @param codes the error codes to write.
* @throws IOException if an error occurs.
*/
private void writeErrorsFromEnum(JsonGenerator generator, ErrorCode[] codes) throws IOException {
for (ErrorCode code : codes) {
// cast to JsonErrorCode needed to ease json handling
JsonErrorCodeDescription description = new JsonErrorCodeDescription(code);
generator.writeObject(description);
}
}
use of org.talend.daikon.exception.error.ErrorCode in project data-prep by Talend.
the class ErrorMessageTest method shouldReturnRightErrorMessageWhenHttpStatusIs500.
@Test
public void shouldReturnRightErrorMessageWhenHttpStatusIs500() {
// given
ErrorCode errorCode = new ErrorCode() {
@Override
public String getProduct() {
return "TDP";
}
@Override
public String getGroup() {
return "API";
}
@Override
public int getHttpStatus() {
return 500;
}
@Override
public Collection<String> getExpectedContextEntries() {
return Collections.emptyList();
}
@Override
public String getCode() {
return null;
}
};
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("An unexpected error occurred and we could not complete your last operation. You can continue to use Data Preparation", exception.getMessage());
assertEquals("An error has occurred", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
use of org.talend.daikon.exception.error.ErrorCode in project data-prep by Talend.
the class ErrorMessageTest method shouldReturnRightErrorMessageWhenDatasetStillInUseThrown.
@Test
public void shouldReturnRightErrorMessageWhenDatasetStillInUseThrown() {
// given
ErrorCode errorCode = DATASET_STILL_IN_USE;
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("You cannot delete the dataset, it is being used by preparation(s)", exception.getMessage());
assertEquals("Deletion forbidden", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
use of org.talend.daikon.exception.error.ErrorCode in project data-prep by Talend.
the class ErrorMessageTest method shouldReturnRightErrorMessageWhenPreparationStepCannotBeDeletedInSingleModeThrown.
@Test
public void shouldReturnRightErrorMessageWhenPreparationStepCannotBeDeletedInSingleModeThrown() {
// given
ErrorCode errorCode = PREPARATION_STEP_CANNOT_BE_DELETED_IN_SINGLE_MODE;
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("This action cannot be deleted because subsequent actions depend on it", exception.getMessage());
assertEquals("Delete action not authorized", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
use of org.talend.daikon.exception.error.ErrorCode in project data-prep by Talend.
the class ErrorMessageTest method shouldReturnRightErrorMessageWhenUnsupportedContentThrown.
@Test
public void shouldReturnRightErrorMessageWhenUnsupportedContentThrown() {
// given
ErrorCode errorCode = UNSUPPORTED_CONTENT;
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("Unable to create dataset, content is not supported. Try with a csv or xls file!", exception.getMessage());
assertEquals("Unsupported content", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
Aggregations