Search in sources :

Example 1 with ErrorReport

use of org.sklsft.commons.api.exception.ErrorReport in project skeleton-commons by skeleton-software-community.

the class ErrorReportHandler method handleError.

/*
	 * (non-Javadoc)
	 * @see org.springframework.web.client.ResponseErrorHandler#handleError(org.springframework.http.client.ClientHttpResponse)
	 */
@Override
public void handleError(ClientHttpResponse response) throws IOException {
    ErrorReport errorReport = objectMapper.readValue(response.getBody(), ErrorReport.class);
    convertErrorReport(errorReport);
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport)

Example 2 with ErrorReport

use of org.sklsft.commons.api.exception.ErrorReport in project skeleton-commons by skeleton-software-community.

the class ErrorReportHandlerTest method testApplicationExceptionDummyDetails.

@Test
public void testApplicationExceptionDummyDetails() throws JsonProcessingException {
    String message = "test";
    Dummy dummy = new Dummy(1L, "test");
    ErrorReport errorReport = new ErrorReport();
    errorReport.setExceptionClassName(TestException.class.getName());
    errorReport.setMessage(message);
    errorReport.setDetails(dummy);
    try {
        errorReportHandler.convertErrorReport(errorReport);
    } catch (ApplicationException e) {
        Assert.assertEquals(e.getMessage(), message);
        Assert.assertTrue(e instanceof TestException);
        Assert.assertTrue(e.getDetails().equals(dummy));
        return;
    }
    Assert.fail();
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport) ApplicationException(org.sklsft.commons.api.exception.ApplicationException) Test(org.junit.Test)

Example 3 with ErrorReport

use of org.sklsft.commons.api.exception.ErrorReport in project skeleton-commons by skeleton-software-community.

the class RestExceptionHandler method handleException.

@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
@ResponseBody
public ErrorReport handleException(Exception e) {
    logger.error("exception thrown : " + e.getMessage(), e);
    ErrorReport errorReport = new ErrorReport();
    errorReport.setExceptionClassName(TechnicalError.class.getName());
    errorReport.setMessage(ApplicationException.ERROR_UNKNOWN);
    return errorReport;
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport) TechnicalError(org.sklsft.commons.api.exception.TechnicalError) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ErrorReport

use of org.sklsft.commons.api.exception.ErrorReport in project skeleton-commons by skeleton-software-community.

the class RestExceptionHandlerTest method testApplicationExceptionNoDetails.

@Test
public void testApplicationExceptionNoDetails() {
    String message = "test";
    ApplicationException e = new TestException(message);
    ErrorReport errorReport = restExceptionHandler.handleApplicationException(e);
    Assert.assertEquals(errorReport.getMessage(), message);
    Assert.assertTrue(errorReport.getExceptionClassName().equals(TestException.class.getName()));
    Assert.assertNull(errorReport.getDetails());
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport) ApplicationException(org.sklsft.commons.api.exception.ApplicationException) Test(org.junit.Test)

Example 5 with ErrorReport

use of org.sklsft.commons.api.exception.ErrorReport in project skeleton-commons by skeleton-software-community.

the class ErrorReportHandlerTest method testApplicationExceptionNoDetails.

@Test
public void testApplicationExceptionNoDetails() throws JsonProcessingException {
    String message = "test";
    ErrorReport errorReport = new ErrorReport();
    errorReport.setExceptionClassName(TestException.class.getName());
    errorReport.setMessage(message);
    try {
        errorReportHandler.convertErrorReport(errorReport);
    } catch (ApplicationException e) {
        Assert.assertEquals(e.getMessage(), message);
        Assert.assertTrue(e instanceof TestException);
        Assert.assertNull(e.getDetails());
        return;
    }
    Assert.fail();
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport) ApplicationException(org.sklsft.commons.api.exception.ApplicationException) Test(org.junit.Test)

Aggregations

ErrorReport (org.sklsft.commons.api.exception.ErrorReport)7 Test (org.junit.Test)4 ApplicationException (org.sklsft.commons.api.exception.ApplicationException)4 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 TechnicalError (org.sklsft.commons.api.exception.TechnicalError)1