@Test public void itReturnsGenericErrorForUnmodeledExceptions() throws Exception { PojoTestException e = new PojoTestException("some value", "another value", new RuntimeException("oh dear!")); JsonError error = resolver.resolveError( e, PojoService.class.getMethod("nonPojoCall", String.class), Arrays.asList(new TextNode("foo"))); JsonNode node = mapper.valueToTree(error); assertThat(node) .hasField("code", JsonError.INTERNAL_ERROR.code) .hasField("message", "some value:another value") .hasNullField("data"); }
@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; }