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