Class DittoRuntimeException

    • Constructor Detail

      • DittoRuntimeException

        protected DittoRuntimeException​(String errorCode,
                                        HttpStatusCode statusCode,
                                        DittoHeaders dittoHeaders,
                                        @Nullable
                                        String message,
                                        @Nullable
                                        String description,
                                        @Nullable
                                        Throwable cause,
                                        @Nullable
                                        URI href)
        Constructs a new DittoRuntimeException object.
        Parameters:
        errorCode - a code which uniquely identifies the exception.
        statusCode - the HTTP status code.
        dittoHeaders - the headers with which this Exception should be reported back to the user.
        message - the detail message for later retrieval with Throwable.getMessage().
        description - a description with further information about the exception.
        cause - the cause of the exception for later retrieval with Throwable.getCause().
        href - a link to a resource which provides further information about the exception.
        Throws:
        NullPointerException - if errorCode, statusCode or dittoHeaders is null.
    • Method Detail

      • getBuilder

        public DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> getBuilder()
        Construct a builder b such that b.build() has identical class and fields as this.

        A subclass should extend this method if it adds another field.

        Returns:
        A builder to construct an identical copy of this.
      • asDittoRuntimeException

        public static DittoRuntimeException asDittoRuntimeException​(Throwable throwable,
                                                                    Function<Throwable,​DittoRuntimeException> alternativeExceptionBuilder)
        Takes the throwable and tries to map it to a DittoRuntimeException.

        If the throwable is a CompletionException or a ExecutionException, this method tries to map the cause of this exception to a DittoRuntimeException.

        Parameters:
        throwable - the throwable to map.
        alternativeExceptionBuilder - used to build an alternative DittoRuntimeException if the throwable could not be mapped.
        Returns:
        either the mapped exception or the exception built by alternativeExceptionBuilder.
      • newBuilder

        public static DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> newBuilder​(DittoRuntimeException dittoRuntimeException)
        Returns a new mutable builder with a fluent API for a dittoRuntimeException. The builder is already initialized with the properties of the given exception.
        Parameters:
        dittoRuntimeException - the exception to be copied.
        Returns:
        the new builder.
        Throws:
        NullPointerException - if dittoRuntimeException is null.
      • readHRef

        protected static Optional<URI> readHRef​(org.eclipse.ditto.json.JsonObject jsonObject)
      • readMessage

        protected static String readMessage​(org.eclipse.ditto.json.JsonObject jsonObject)
      • readDescription

        protected static Optional<String> readDescription​(org.eclipse.ditto.json.JsonObject jsonObject)
      • getErrorCode

        public String getErrorCode()
        Returns the error code to uniquely identify this exception.
        Returns:
        the error code.
      • getStatusCode

        public HttpStatusCode getStatusCode()
        Retrieves the required HttpStatusCode with which this Exception should be reported back to the user.
        Returns:
        the HttpStatusCode.
      • getDescription

        public Optional<String> getDescription()
        Returns the description which should be reported to the user.
        Returns:
        the description.
      • getHref

        public Optional<URI> getHref()
        Returns a link with which the user can find further information regarding this exception.
        Returns:
        a link to provide the user with further information about this exception.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toJson

        public org.eclipse.ditto.json.JsonObject toJson()
        Returns all non hidden marked fields of this exception.
        Specified by:
        toJson in interface Jsonifiable<org.eclipse.ditto.json.JsonObject>
        Returns:
        a JSON object representation of this exception including only non hidden marked fields.
      • toJson

        public org.eclipse.ditto.json.JsonObject toJson​(JsonSchemaVersion schemaVersion,
                                                        Predicate<org.eclipse.ditto.json.JsonField> thePredicate)
        Description copied from interface: Jsonifiable.WithPredicate
        Returns this object as JsonValue. The content of the result is determined by the given predicate.
        Specified by:
        toJson in interface Jsonifiable.WithPredicate<org.eclipse.ditto.json.JsonObject,​org.eclipse.ditto.json.JsonField>
        Parameters:
        schemaVersion - the JsonSchemaVersion in which to return the JSON.
        thePredicate - determines the content of the result.
        Returns:
        a JSON value representation of this object.
      • appendToJson

        protected void appendToJson​(org.eclipse.ditto.json.JsonObjectBuilder jsonObjectBuilder,
                                    Predicate<org.eclipse.ditto.json.JsonField> predicate)
        Allows to append exception-specific fields to the passed jsonObjectBuilder.
        Parameters:
        jsonObjectBuilder - the JsonObjectBuilder to add the fields to.
        predicate - the predicate to evaluate when adding the payload (already contains the schema version and that the field is not null).
      • fromUnknownErrorJson

        public static Optional<DittoRuntimeException> fromUnknownErrorJson​(org.eclipse.ditto.json.JsonObject jsonObject,
                                                                           DittoHeaders headers)
        Deserialize an error whose java class isn't known.
        Parameters:
        jsonObject - the error object.
        headers - the headers.
        Returns:
        a generic DittoRuntimeException object if the JSON can be parsed as such; an empty optional otherwise.