Search in sources :

Example 6 with ErrorReport

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

the class RestExceptionHandler method handleApplicationException.

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

Example 7 with ErrorReport

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

the class RestExceptionHandlerTest method testApplicationExceptionDummyDetails.

@Test
public void testApplicationExceptionDummyDetails() {
    Dummy dummy = new Dummy();
    dummy.setLongField(1L);
    dummy.setStringField("test");
    String message = "test";
    ApplicationException e = new TestException(message, dummy);
    ErrorReport errorReport = restExceptionHandler.handleApplicationException(e);
    Assert.assertEquals(errorReport.getMessage(), message);
    Assert.assertTrue(errorReport.getExceptionClassName().equals(TestException.class.getName()));
    Assert.assertNotNull(errorReport.getDetails());
    Assert.assertTrue(errorReport.getDetails() instanceof Dummy);
}
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