Search in sources :

Example 1 with DeserializeBodyException

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

the class AbstractRequestHandler method deserializeBody.

protected <T> T deserializeBody(BodyData bodyData, Class<T> type) throws IOException {
    String contentType = bodyData.getContentType();
    if (contentType == null) {
        throw new HttpBadRequestException("contentType is null");
    }
    BodyDeserializer deserializer = dataConverters.getBodyDeserializer(contentType);
    try {
        return deserializer.deserialize(bodyData, type);
    } catch (Exception e) {
        throw new DeserializeBodyException("can't deserialize body data to: " + type.getName(), e);
    }
}
Also used : BodyDeserializer(com.tvd12.ezyhttp.core.codec.BodyDeserializer) DeserializeBodyException(com.tvd12.ezyhttp.core.exception.DeserializeBodyException) HttpBadRequestException(com.tvd12.ezyhttp.core.exception.HttpBadRequestException) DeserializeHeaderException(com.tvd12.ezyhttp.core.exception.DeserializeHeaderException) IOException(java.io.IOException) DeserializePathVariableException(com.tvd12.ezyhttp.core.exception.DeserializePathVariableException) DeserializeBodyException(com.tvd12.ezyhttp.core.exception.DeserializeBodyException) DeserializeCookieException(com.tvd12.ezyhttp.core.exception.DeserializeCookieException) EzyProcessor.processWithLogException(com.tvd12.ezyfox.util.EzyProcessor.processWithLogException) DeserializeParameterException(com.tvd12.ezyhttp.core.exception.DeserializeParameterException) HttpBadRequestException(com.tvd12.ezyhttp.core.exception.HttpBadRequestException)

Example 2 with DeserializeBodyException

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

the class DeserializeBodyExceptionTest method test.

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

Aggregations

DeserializeBodyException (com.tvd12.ezyhttp.core.exception.DeserializeBodyException)2 EzyProcessor.processWithLogException (com.tvd12.ezyfox.util.EzyProcessor.processWithLogException)1 BodyDeserializer (com.tvd12.ezyhttp.core.codec.BodyDeserializer)1 DeserializeCookieException (com.tvd12.ezyhttp.core.exception.DeserializeCookieException)1 DeserializeHeaderException (com.tvd12.ezyhttp.core.exception.DeserializeHeaderException)1 DeserializeParameterException (com.tvd12.ezyhttp.core.exception.DeserializeParameterException)1 DeserializePathVariableException (com.tvd12.ezyhttp.core.exception.DeserializePathVariableException)1 HttpBadRequestException (com.tvd12.ezyhttp.core.exception.HttpBadRequestException)1 IOException (java.io.IOException)1 Test (org.testng.annotations.Test)1