/** * 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); }
@Override protected JsonRuntimeException doBuild(final String errorCode, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new JsonRuntimeException(errorCode, message, description, cause, href); }
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(); } }
/** * Returns a builder for fluently creating instances of {@code JsonRuntimeException}s.. * * @param errorCode a code which uniquely identifies the exception. * @return a new builder for JsonRuntimeException objects. * @throws NullPointerException if {@code errorCode} is {@code null}. * @throws IllegalArgumentException if {@code errorCode} is empty. */ public static JsonExceptionBuilder newBuilder(final String errorCode) { checkErrorCode(errorCode); return new Builder(errorCode); }
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(); } }
/** * Returns a builder for fluently creating instances of {@code JsonRuntimeException}s.. * * @param errorCode a code which uniquely identifies the exception. * @return a new builder for JsonRuntimeException objects. * @throws NullPointerException if {@code errorCode} is {@code null}. * @throws IllegalArgumentException if {@code errorCode} is empty. */ public static JsonExceptionBuilder newBuilder(final String errorCode) { checkErrorCode(errorCode); return new Builder(errorCode); }
/** * 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 JsonRuntimeException} object with the specified values. * * @param errorCode the error code of the exception. * @param message the detail message for later retrieval with {@link #getMessage()}. * @param description a description with further information about the exception. * @param cause the cause of the exception for later retrieval with {@link #getCause()}. * @param href a link to a resource which provides further information about the exception. * @throws NullPointerException if {@code errorCode} is {@code null}. * @throws IllegalArgumentException if {@code errorCode} is empty. */ protected JsonRuntimeException(final String errorCode, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { super(message, cause); checkErrorCode(errorCode); this.errorCode = errorCode; this.description = description; this.href = href; }
@Override protected JsonRuntimeException doBuild(final String errorCode, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new JsonRuntimeException(errorCode, message, description, cause, href); }
/** * Constructs a new {@code JsonRuntimeException} object with the specified values. * * @param errorCode the error code of the exception. * @param message the detail message for later retrieval with {@link #getMessage()}. * @param description a description with further information about the exception. * @param cause the cause of the exception for later retrieval with {@link #getCause()}. * @param href a link to a resource which provides further information about the exception. * @throws NullPointerException if {@code errorCode} is {@code null}. * @throws IllegalArgumentException if {@code errorCode} is empty. */ protected JsonRuntimeException(final String errorCode, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { super(message, cause); checkErrorCode(errorCode); this.errorCode = errorCode; this.description = description; this.href = href; }