use of com.tvd12.ezyhttp.core.exception.HttpRequestException 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.HttpRequestException in project ezyhttp by youngmonkeys.
the class HttpRequestExceptionTest method test.
@Test
public void test() {
// given
int code = StatusCodes.BAD_REQUEST;
String data = "error";
// when
HttpRequestException sut = new HttpRequestException(code, data);
// then
Asserts.assertEquals(code, sut.getCode());
Asserts.assertEquals(data, sut.getData());
}
Aggregations