/** * Constructs a new {@code DittoJsonException} by wrapping the specified {@link JsonRuntimeException} or * {@link RuntimeException} and adding the given command headers. * * @param toWrap the {@link JsonRuntimeException} or {@code RuntimeException} to be wrapped. * @param dittoHeaders the command headers to be added. */ public DittoJsonException(final RuntimeException toWrap, final DittoHeaders dittoHeaders) { super( toWrap instanceof JsonRuntimeException ? ((JsonRuntimeException) toWrap).getErrorCode() : FALLBACK_ERROR_CODE, HttpStatusCode.BAD_REQUEST, dittoHeaders, toWrap.getMessage(), toWrap instanceof JsonRuntimeException ? ((JsonRuntimeException) toWrap).getDescription().orElse(null) : null, toWrap.getCause(), toWrap instanceof JsonRuntimeException ? ((JsonRuntimeException) toWrap).getHref().orElse(null) : null); }
/** * Constructs a new {@code DittoJsonException} by wrapping the specified {@link JsonRuntimeException} or * {@link RuntimeException} and adding the given command headers. * * @param toWrap the {@link JsonRuntimeException} or {@code RuntimeException} to be wrapped. * @param dittoHeaders the command headers to be added. */ public DittoJsonException(final RuntimeException toWrap, final DittoHeaders dittoHeaders) { super( toWrap instanceof JsonRuntimeException ? ((JsonRuntimeException) toWrap).getErrorCode() : FALLBACK_ERROR_CODE, HttpStatusCode.BAD_REQUEST, dittoHeaders, toWrap.getMessage(), toWrap instanceof JsonRuntimeException ? ((JsonRuntimeException) toWrap).getDescription().orElse(null) : null, toWrap.getCause(), toWrap instanceof JsonRuntimeException ? ((JsonRuntimeException) toWrap).getHref().orElse(null) : null); }
private T fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final String type = resolveType(jsonObject); final JsonParsable<T> jsonObjectParsable = parseStrategies.get(type); if (null != jsonObjectParsable) { try { return jsonObjectParsable.parse(jsonObject, dittoHeaders); } catch (final JsonRuntimeException jre) { final JsonExceptionBuilder builder = JsonRuntimeException.newBuilder(jre.getErrorCode()) .message("Error when parsing Json type '" + type + "': " + jre.getMessage()) .cause(jre.getCause()); jre.getDescription().ifPresent(builder::description); jre.getHref().ifPresent(builder::href); // rethrow after enhancing the exception with the type which failed to parse throw (JsonRuntimeException) builder.build(); } } else { throw JsonTypeNotParsableException.newBuilder(type, getClass().getSimpleName()) .dittoHeaders(dittoHeaders) .build(); } }
private T fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final String type = resolveType(jsonObject); final JsonParsable<T> jsonObjectParsable = parseStrategies.get(type); if (null != jsonObjectParsable) { try { return jsonObjectParsable.parse(jsonObject, dittoHeaders); } catch (final JsonRuntimeException jre) { final JsonExceptionBuilder builder = JsonRuntimeException.newBuilder(jre.getErrorCode()) .message("Error when parsing Json type '" + type + "': " + jre.getMessage()) .cause(jre.getCause()); jre.getDescription().ifPresent(builder::description); jre.getHref().ifPresent(builder::href); // rethrow after enhancing the exception with the type which failed to parse throw (JsonRuntimeException) builder.build(); } } else { throw JsonTypeNotParsableException.newBuilder(type, getClass().getSimpleName()) .dittoHeaders(dittoHeaders) .build(); } }