Search in sources :

Example 1 with ErrorCode

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);
    }
}
Also used : JsonErrorCodeDescription(org.talend.dataprep.exception.json.JsonErrorCodeDescription) ErrorCode(org.talend.daikon.exception.error.ErrorCode)

Example 2 with ErrorCode

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

Example 3 with ErrorCode

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

Example 4 with ErrorCode

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

Example 5 with ErrorCode

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());
}
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