/** * Deserialize an error whose java class isn't known. * * @param jsonObject the error object. * @param headers the headers. * @return a generic {@code DittoRuntimeException} object if the JSON can be parsed as such; an empty optional * otherwise. */ public static Optional<DittoRuntimeException> fromUnknownErrorJson(final JsonObject jsonObject, final DittoHeaders headers) { return jsonObject.getValue(JsonFields.ERROR_CODE).flatMap(errorCode -> jsonObject.getValue(JsonFields.STATUS).flatMap(HttpStatusCode::forInt).map(status -> { final Builder builder = new Builder(errorCode, status); builder.dittoHeaders(headers); jsonObject.getValue(JsonFields.MESSAGE).ifPresent(builder::message); jsonObject.getValue(JsonFields.DESCRIPTION).ifPresent(builder::description); jsonObject.getValue(JsonFields.HREF) .flatMap(uriString -> { try { return Optional.of(new URI(uriString)); } catch (URISyntaxException e) { return Optional.empty(); } }) .ifPresent(builder::href); return builder.build(); }) ); }
DittoRuntimeException.newBuilder(errorCode, HttpStatusCode.forInt(status).orElse(HttpStatusCode.INTERNAL_SERVER_ERROR)) .message(errorMessage) .description(errorDescription) .dittoHeaders(dittoHeaders)
DittoRuntimeException.newBuilder(errorCode, HttpStatusCode.forInt(status).orElse(HttpStatusCode.INTERNAL_SERVER_ERROR)) .message(errorMessage) .description(errorDescription) .dittoHeaders(dittoHeaders)
/** * Deserialize an error whose java class isn't known. * * @param jsonObject the error object. * @param headers the headers. * @return a generic {@code DittoRuntimeException} object if the JSON can be parsed as such; an empty optional * otherwise. */ public static Optional<DittoRuntimeException> fromUnknownErrorJson(final JsonObject jsonObject, final DittoHeaders headers) { return jsonObject.getValue(JsonFields.ERROR_CODE).flatMap(errorCode -> jsonObject.getValue(JsonFields.STATUS).flatMap(HttpStatusCode::forInt).map(status -> { final Builder builder = new Builder(errorCode, status); builder.dittoHeaders(headers); jsonObject.getValue(JsonFields.MESSAGE).ifPresent(builder::message); jsonObject.getValue(JsonFields.DESCRIPTION).ifPresent(builder::description); jsonObject.getValue(JsonFields.HREF) .flatMap(uriString -> { try { return Optional.of(new URI(uriString)); } catch (URISyntaxException e) { return Optional.empty(); } }) .ifPresent(builder::href); return builder.build(); }) ); }
/** * Returns a new mutable builder for fluently creating instances of {@code DittoRuntimeException}s.. * * @param errorCode a code which uniquely identifies the exception. * @param statusCode the HTTP status code. * @return the new builder. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code errorCode} is empty. */ public static Builder newBuilder(final String errorCode, final HttpStatusCode statusCode) { return new Builder(errorCode, statusCode); }
/** * Each subclass should override this method to provide an implementation of {@code * DittoRuntimeExceptionBuilder}. * <p> * Per default, an instance {@link Builder} is used, which builds a generic {@code DittoRuntimeException}. * * @return A builder to construct a DittoRuntimeException. */ protected DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> getEmptyBuilder() { return new Builder(errorCode, statusCode); }
/** * Returns a new mutable builder for fluently creating instances of {@code DittoRuntimeException}s.. * * @param errorCode a code which uniquely identifies the exception. * @param statusCode the HTTP status code. * @return the new builder. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code errorCode} is empty. */ public static Builder newBuilder(final String errorCode, final HttpStatusCode statusCode) { return new Builder(errorCode, statusCode); }
/** * Each subclass should override this method to provide an implementation of {@code * DittoRuntimeExceptionBuilder}. * <p> * Per default, an instance {@link Builder} is used, which builds a generic {@code DittoRuntimeException}. * * @return A builder to construct a DittoRuntimeException. */ protected DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> getEmptyBuilder() { return new Builder(errorCode, statusCode); }