@Test public void itReturnsNullForNonErrorResponse() { ObjectNode response = response(null); Throwable throwable = resolver.resolveException(response); assertThat(throwable).isNull(); }
@Override public Throwable resolveException(final ObjectNode response) { log.trace("Resolving exception from JSON response {}", response); final JsonNode error = response.get(JsonRpcBasicServer.ERROR); if (error == null || !error.isObject()) { log.warn("No error information found in JSON response {}", response); return null; } final JsonNode code = error.get(JsonRpcBasicServer.ERROR_CODE); if (code == null || !code.isInt() || code.asInt() != ThrowableSerializationMixin.ERROR_CODE) { log.warn("Not resolving exception for unsupported error code {}", code); return null; } final JsonNode data = error.get(JsonRpcBasicServer.DATA); if (data == null || !data.isObject()) { log.warn("No error details included in data field of JSON error {}", error); return null; } final ObjectNode dataObject = ((ObjectNode) data); if (!dataObject.has(JsonRpcBasicServer.ERROR_MESSAGE)) { dataObject.set( JsonRpcBasicServer.ERROR_MESSAGE, new TextNode(error.get(JsonRpcBasicServer.ERROR_MESSAGE).asText())); } try { return mapper.treeToValue(data, Throwable.class); } catch (final JsonProcessingException e) { log.warn("Unable to convert JSON response error '{}' into Throwable", data, e); return null; } }
PojoExceptionResolver implements ExceptionResolver { @Override public Throwable resolveException(final ObjectNode response) { log.trace("Resolving exception from JSON response {}", response); final JsonNode error = response.get(JsonRpcBasicServer.ERROR); if (error == null || !error.isObject()) { log.warn("No error information found in JSON response {}", response); return null; } final JsonNode code = error.get(JsonRpcBasicServer.ERROR_CODE); if (code == null || !code.isInt() || code.asInt() != ThrowableSerializationMixin.ERROR_CODE) { log.warn("Not resolving exception for unsupported error code {}", code); return null; } final JsonNode data = error.get(JsonRpcBasicServer.DATA); if (data == null || !data.isObject()) { log.warn("No error details included in data field of JSON error {}", error); return null; } final ObjectNode dataObject = ((ObjectNode) data); if (!dataObject.has(JsonRpcBasicServer.ERROR_MESSAGE)) { dataObject.set( JsonRpcBasicServer.ERROR_MESSAGE, new TextNode(error.get(JsonRpcBasicServer.ERROR_MESSAGE).asText())); } try { return mapper.treeToValue(data, Throwable.class); } catch (final JsonProcessingException e) { log.warn("Unable to convert JSON response error '{}' into Throwable", data, e); return null; } } }
PojoExceptionResolver implements ExceptionResolver { @Override public Throwable resolveException(final ObjectNode response) { log.trace("Resolving exception from JSON response {}", response); final JsonNode error = response.get(JsonRpcBasicServer.ERROR); if (error == null || !error.isObject()) { log.warn("No error information found in JSON response {}", response); return null; } final JsonNode code = error.get(JsonRpcBasicServer.ERROR_CODE); if (code == null || !code.isInt() || code.asInt() != ThrowableSerializationMixin.ERROR_CODE) { log.warn("Not resolving exception for unsupported error code {}", code); return null; } final JsonNode data = error.get(JsonRpcBasicServer.DATA); if (data == null || !data.isObject()) { log.warn("No error details included in data field of JSON error {}", error); return null; } final ObjectNode dataObject = ((ObjectNode) data); if (!dataObject.has(JsonRpcBasicServer.ERROR_MESSAGE)) { dataObject.set( JsonRpcBasicServer.ERROR_MESSAGE, new TextNode(error.get(JsonRpcBasicServer.ERROR_MESSAGE).asText())); } try { return mapper.treeToValue(data, Throwable.class); } catch (final JsonProcessingException e) { log.warn("Unable to convert JSON response error '{}' into Throwable", data, e); return null; } } PojoExceptionResolver(final ObjectMapper mapper); }
PojoExceptionResolver implements ExceptionResolver { @Override public Throwable resolveException(final ObjectNode response) { log.trace("Resolving exception from JSON response {}", response); final JsonNode error = response.get(JsonRpcBasicServer.ERROR); if (error == null || !error.isObject()) { log.warn("No error information found in JSON response {}", response); return null; } final JsonNode code = error.get(JsonRpcBasicServer.ERROR_CODE); if (code == null || !code.isInt() || code.asInt() != ThrowableSerializationMixin.ERROR_CODE) { log.warn("Not resolving exception for unsupported error code {}", code); return null; } final JsonNode data = error.get(JsonRpcBasicServer.DATA); if (data == null || !data.isObject()) { log.warn("No error details included in data field of JSON error {}", error); return null; } final ObjectNode dataObject = ((ObjectNode) data); if (!dataObject.has(JsonRpcBasicServer.ERROR_MESSAGE)) { dataObject.set( JsonRpcBasicServer.ERROR_MESSAGE, new TextNode(error.get(JsonRpcBasicServer.ERROR_MESSAGE).asText())); } try { return mapper.treeToValue(data, Throwable.class); } catch (final JsonProcessingException e) { log.warn("Unable to convert JSON response error '{}' into Throwable", data, e); return null; } } PojoExceptionResolver(final ObjectMapper mapper); @Override Throwable resolveException(final ObjectNode response); }
PojoExceptionResolver implements ExceptionResolver { @Override public Throwable resolveException(final ObjectNode response) { log.trace("Resolving exception from JSON response {}", response); final JsonNode error = response.get(JsonRpcBasicServer.ERROR); if (error == null || !error.isObject()) { log.warn("No error information found in JSON response {}", response); return null; } final JsonNode code = error.get(JsonRpcBasicServer.ERROR_CODE); if (code == null || !code.isInt() || code.asInt() != ThrowableSerializationMixin.ERROR_CODE) { log.warn("Not resolving exception for unsupported error code {}", code); return null; } final JsonNode data = error.get(JsonRpcBasicServer.DATA); if (data == null || !data.isObject()) { log.warn("No error details included in data field of JSON error {}", error); return null; } final ObjectNode dataObject = ((ObjectNode) data); if (!dataObject.has(JsonRpcBasicServer.ERROR_MESSAGE)) { dataObject.set( JsonRpcBasicServer.ERROR_MESSAGE, new TextNode(error.get(JsonRpcBasicServer.ERROR_MESSAGE).asText())); } try { return mapper.treeToValue(data, Throwable.class); } catch (final JsonProcessingException e) { log.warn("Unable to convert JSON response error '{}' into Throwable", data, e); return null; } } PojoExceptionResolver(final ObjectMapper mapper); @Override Throwable resolveException(final ObjectNode response);  }