Search in sources :

Example 1 with DeserializeValueException

use of com.tvd12.ezyhttp.core.exception.DeserializeValueException in project ezyhttp by youngmonkeys.

the class BlockingServlet method addDefaultExceptionHandlers.

protected void addDefaultExceptionHandlers() {
    exceptionHandlerManager.addUncaughtExceptionHandler(DeserializeValueException.class, (args, e) -> {
        DeserializeValueException deException = (DeserializeValueException) e;
        Map<String, String> errorData = new HashMap<>();
        errorData.put(deException.getValueName(), "invalid");
        errorData.put("exception", e.getClass().getName());
        return ResponseEntity.create(StatusCodes.BAD_REQUEST, errorData);
    });
    exceptionHandlerManager.addUncaughtExceptionHandler(HttpRequestException.class, (args, e) -> {
        HttpRequestException requestException = (HttpRequestException) e;
        int errorStatus = requestException.getCode();
        Object errorData = requestException.getData();
        if (errorData == null) {
            errorData = Collections.emptyMap();
        }
        return ResponseEntity.create(errorStatus, errorData);
    });
}
Also used : DeserializeValueException(com.tvd12.ezyhttp.core.exception.DeserializeValueException) HashMap(java.util.HashMap) HttpRequestException(com.tvd12.ezyhttp.core.exception.HttpRequestException)

Example 2 with DeserializeValueException

use of com.tvd12.ezyhttp.core.exception.DeserializeValueException in project ezyhttp by youngmonkeys.

the class DeserializeValueExceptionTest method test.

@Test
public void test() {
    // given
    Exception e = new Exception("just test");
    // when
    DeserializeValueException sut = new DeserializeValueException("hello", "world", Map.class, e);
    // then
    Asserts.assertEquals("hello", sut.getValueName());
    Asserts.assertEquals("world", sut.getValue());
    Asserts.assertEquals(Map.class, sut.getOutType());
    Asserts.assertEquals(e, sut.getCause());
}
Also used : DeserializeValueException(com.tvd12.ezyhttp.core.exception.DeserializeValueException) DeserializeValueException(com.tvd12.ezyhttp.core.exception.DeserializeValueException) Test(org.testng.annotations.Test)

Example 3 with DeserializeValueException

use of com.tvd12.ezyhttp.core.exception.DeserializeValueException in project ezyhttp by youngmonkeys.

the class DeserializeValueExceptionTest method valueNull.

@Test
public void valueNull() {
    // given
    Exception e = new Exception("just test");
    // when
    DeserializeValueException sut = new DeserializeValueException("hello", null, Map.class, e);
    // then
    Asserts.assertEquals("hello", sut.getValueName());
    Asserts.assertNull(sut.getValue());
    Asserts.assertEquals(Map.class, sut.getOutType());
    Asserts.assertEquals(e, sut.getCause());
}
Also used : DeserializeValueException(com.tvd12.ezyhttp.core.exception.DeserializeValueException) DeserializeValueException(com.tvd12.ezyhttp.core.exception.DeserializeValueException) Test(org.testng.annotations.Test)

Aggregations

DeserializeValueException (com.tvd12.ezyhttp.core.exception.DeserializeValueException)3 Test (org.testng.annotations.Test)2 HttpRequestException (com.tvd12.ezyhttp.core.exception.HttpRequestException)1 HashMap (java.util.HashMap)1