Search in sources :

Example 6 with ErrorCode

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);
}
Also used : HashMap(java.util.HashMap) JsonErrorCode(org.talend.daikon.exception.json.JsonErrorCode) ErrorCode(org.talend.daikon.exception.error.ErrorCode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ErrorCode

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());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 8 with ErrorCode

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());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 9 with ErrorCode

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());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 10 with ErrorCode

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());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Aggregations

ErrorCode (org.talend.daikon.exception.error.ErrorCode)10 Test (org.junit.Test)8 ServiceBaseTest (org.talend.ServiceBaseTest)8 TDPException (org.talend.dataprep.exception.TDPException)8 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JsonErrorCode (org.talend.daikon.exception.json.JsonErrorCode)1 JsonErrorCodeDescription (org.talend.dataprep.exception.json.JsonErrorCodeDescription)1