use of org.talend.daikon.exception.error.ErrorCode in project data-prep by Talend.
the class TDPException method toExceptionDto.
// Needed to keep the compatibility with the deprecated writeTo(Writer) method.
// This code duplicates the one in ExceptionsConfiguration and should not be used anywhere else.
private static TdpExceptionDto toExceptionDto(TalendRuntimeException internal) {
ErrorCode errorCode = internal.getCode();
String serializedCode = errorCode.getProduct() + '_' + errorCode.getGroup() + '_' + errorCode.getCode();
String defaultMessage = internal.getMessage();
String message = internal.getLocalizedMessage();
String messageTitle = internal instanceof TDPException ? ((TDPException) internal).getMessageTitle() : null;
TdpExceptionDto cause = internal.getCause() instanceof TDPException ? toExceptionDto((TDPException) internal.getCause()) : null;
Map<String, Object> context = new HashMap<>();
for (Map.Entry<String, Object> contextEntry : internal.getContext().entries()) {
context.put(contextEntry.getKey(), contextEntry.getValue());
}
return new TdpExceptionDto(serializedCode, cause, defaultMessage, message, messageTitle, context);
}
use of org.talend.daikon.exception.error.ErrorCode in project data-prep by Talend.
the class ErrorMessageTest method shouldReturnRightErrorMessageWhenHttpStatusIsZero.
@Test
public void shouldReturnRightErrorMessageWhenHttpStatusIsZero() {
// given
ErrorCode errorCode = new ErrorCode() {
@Override
public String getProduct() {
return "TDP";
}
@Override
public String getGroup() {
return "API";
}
@Override
public int getHttpStatus() {
return 0;
}
@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("Service unavailable", 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 shouldReturnRightErrorMessageWhenUnableToCreateDatasetThrown.
@Test
public void shouldReturnRightErrorMessageWhenUnableToCreateDatasetThrown() {
// given
ErrorCode errorCode = UNABLE_TO_CREATE_DATASET;
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("An error occurred during import", exception.getMessage());
assertEquals("Import error", 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 shouldReturnRightErrorMessageWhenDefaultErrorThrown.
@Test
public void shouldReturnRightErrorMessageWhenDefaultErrorThrown() {
// given
ErrorCode errorCode = new ErrorCode() {
@Override
public String getProduct() {
return "TDP";
}
@Override
public String getGroup() {
return "API";
}
@Override
public int getHttpStatus() {
return 404;
}
@Override
public Collection<String> getExpectedContextEntries() {
return Collections.emptyList();
}
@Override
public String getCode() {
return null;
}
};
// when
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 shouldReturnRightErrorMessageWhenUnableToCreateOrUpdateDatasetThrown.
@Test
public void shouldReturnRightErrorMessageWhenUnableToCreateOrUpdateDatasetThrown() {
// given
ErrorCode errorCode = UNABLE_TO_CREATE_OR_UPDATE_DATASET;
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("An error occurred during update", exception.getMessage());
assertEquals("Update error", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
Aggregations