@Test public void itPreservesErrorInformationForModeledExceptions() throws Exception { PojoTestException e = new PojoTestException("some value", "another value", new RuntimeException("oh dear!")); JsonError error = resolver.resolveError( e, PojoService.class.getMethod("pojoCall", String.class), Arrays.asList(new TextNode("foo"))); JsonNode node = mapper.valueToTree(error); assertThat(node) .hasField("code", PojoErrorResolver.ERROR_CODE) .hasField("message", "some value:another value"); JsonNode data = node.get("data"); assertThat(data) .hasField(JsonRpcBasicServer.EXCEPTION_TYPE_NAME, PojoTestException.class.getName()) .hasField("someValue", "some value") .hasField("anotherValue", "another value") .hasNoField("cause") .hasNoField("stackTrace") .hasNoField("suppressed") .hasNoField("localisedMessage"); }
@Override public JsonError resolveError( final Throwable t, final Method method, final List<JsonNode> arguments) { final boolean isModeledException = Arrays.stream(method.getExceptionTypes()).anyMatch(aClass -> aClass.isInstance(t)); if (isModeledException) { final JsonNode node = mapper.valueToTree(t); return new JsonError(ERROR_CODE, t.getMessage(), node); } log.warn( "Exception type {} is not modeled in signature of {}, returning generic error", t.getClass(), method.getName()); return new JsonError(JsonError.INTERNAL_ERROR.code, t.getMessage(), null); }
PojoErrorResolver implements ErrorResolver { @Override public JsonError resolveError( final Throwable t, final Method method, final List<JsonNode> arguments) { final boolean isModeledException = Arrays.stream(method.getExceptionTypes()).anyMatch(aClass -> aClass.isInstance(t)); if (isModeledException) { final JsonNode node = mapper.valueToTree(t); return new JsonError(ERROR_CODE, t.getMessage(), node); } log.warn( "Exception type {} is not modeled in signature of {}, returning generic error", t.getClass(), method.getName()); return new JsonError(JsonError.INTERNAL_ERROR.code, t.getMessage(), null); } }
PojoErrorResolver implements ErrorResolver { @Override public JsonError resolveError( final Throwable t, final Method method, final List<JsonNode> arguments) { final boolean isModeledException = Arrays.stream(method.getExceptionTypes()).anyMatch(aClass -> aClass.isInstance(t)); if (isModeledException) { final JsonNode node = mapper.valueToTree(t); return new JsonError(ERROR_CODE, t.getMessage(), node); } log.warn( "Exception type {} is not modeled in signature of {}, returning generic error", t.getClass(), method.getName()); return new JsonError(JsonError.INTERNAL_ERROR.code, t.getMessage(), null); } PojoErrorResolver(final ObjectMapper mapper); }
PojoErrorResolver implements ErrorResolver { @Override public JsonError resolveError( final Throwable t, final Method method, final List<JsonNode> arguments) { final boolean isModeledException = Arrays.stream(method.getExceptionTypes()).anyMatch(aClass -> aClass.isInstance(t)); if (isModeledException) { final JsonNode node = mapper.valueToTree(t); return new JsonError(ERROR_CODE, t.getMessage(), node); } log.warn( "Exception type {} is not modeled in signature of {}, returning generic error", t.getClass(), method.getName()); return new JsonError(JsonError.INTERNAL_ERROR.code, t.getMessage(), null); } PojoErrorResolver(final ObjectMapper mapper); @Override JsonError resolveError(
      final Throwable t, final Method method, final List<JsonNode> arguments); }
PojoErrorResolver implements ErrorResolver { @Override public JsonError resolveError( final Throwable t, final Method method, final List<JsonNode> arguments) { final boolean isModeledException = Arrays.stream(method.getExceptionTypes()).anyMatch(aClass -> aClass.isInstance(t)); if (isModeledException) { final JsonNode node = mapper.valueToTree(t); return new JsonError(ERROR_CODE, t.getMessage(), node); } log.warn( "Exception type {} is not modeled in signature of {}, returning generic error", t.getClass(), method.getName()); return new JsonError(JsonError.INTERNAL_ERROR.code, t.getMessage(), null); } PojoErrorResolver(final ObjectMapper mapper); @Override JsonError resolveError(
      final Throwable t, final Method method, final List<JsonNode> arguments); static final int ERROR_CODE; }