Class DittoRuntimeException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- org.eclipse.ditto.model.base.exceptions.DittoRuntimeException
-
- All Implemented Interfaces:
Serializable
,WithDittoHeaders<DittoRuntimeException>
,WithManifest
,Jsonifiable<org.eclipse.ditto.json.JsonObject>
,Jsonifiable.WithPredicate<org.eclipse.ditto.json.JsonObject,org.eclipse.ditto.json.JsonField>
- Direct Known Subclasses:
AcknowledgementLabelInvalidException
,AcknowledgementRequestParseException
,DittoHeaderInvalidException
,DittoHeadersTooLargeException
,DittoJsonException
,InvalidRqlExpressionException
,NamespacedEntityIdInvalidException
,SignalEnrichmentFailedException
,TooManyRequestsException
,UnsupportedMediaTypeException
@IndexSubclasses public class DittoRuntimeException extends RuntimeException implements Jsonifiable.WithPredicate<org.eclipse.ditto.json.JsonObject,org.eclipse.ditto.json.JsonField>, WithDittoHeaders<DittoRuntimeException>, WithManifest
Parent RuntimeException for all RuntimeExceptions of Ditto.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DittoRuntimeException.Builder
A mutable builder with a fluent API for aDittoRuntimeException
.static class
DittoRuntimeException.JsonFields
An enumeration of the knownJsonField
s of aDittoRuntimeException
.-
Nested classes/interfaces inherited from interface org.eclipse.ditto.model.base.json.Jsonifiable
Jsonifiable.WithFieldSelector, Jsonifiable.WithFieldSelectorAndPredicate<T>, Jsonifiable.WithPointer<J extends org.eclipse.ditto.json.JsonValue>, Jsonifiable.WithPredicate<J extends org.eclipse.ditto.json.JsonValue,T>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DittoRuntimeException(String errorCode, HttpStatusCode statusCode, DittoHeaders dittoHeaders, String message, String description, Throwable cause, URI href)
Constructs a newDittoRuntimeException
object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
appendToJson(org.eclipse.ditto.json.JsonObjectBuilder jsonObjectBuilder, Predicate<org.eclipse.ditto.json.JsonField> predicate)
Allows to append exception-specific fields to the passedjsonObjectBuilder
.static DittoRuntimeException
asDittoRuntimeException(Throwable throwable, Function<Throwable,DittoRuntimeException> alternativeExceptionBuilder)
Takes the throwable and tries to map it to a DittoRuntimeException.boolean
equals(Object o)
static Optional<DittoRuntimeException>
fromUnknownErrorJson(org.eclipse.ditto.json.JsonObject jsonObject, DittoHeaders headers)
Deserialize an error whose java class isn't known.DittoRuntimeExceptionBuilder<? extends DittoRuntimeException>
getBuilder()
Construct a builderb
such thatb.build()
has identical class and fields asthis
.Optional<String>
getDescription()
Returns the description which should be reported to the user.DittoHeaders
getDittoHeaders()
Returns theDittoHeaders
which are associated with this object.protected DittoRuntimeExceptionBuilder<? extends DittoRuntimeException>
getEmptyBuilder()
Each subclass should override this method to provide an implementation ofDittoRuntimeExceptionBuilder
.String
getErrorCode()
Returns the error code to uniquely identify this exception.Optional<URI>
getHref()
Returns a link with which the user can find further information regarding this exception.JsonSchemaVersion
getImplementedSchemaVersion()
Returns the JsonSchemaVersion the instance of this Jsonifiable implements.String
getManifest()
Returns the manifest (type hint).HttpStatusCode
getStatusCode()
Retrieves the required HttpStatusCode with which this Exception should be reported back to the user.int
hashCode()
static DittoRuntimeException.Builder
newBuilder(String errorCode, HttpStatusCode statusCode)
Returns a new mutable builder for fluently creating instances ofDittoRuntimeException
s..static DittoRuntimeExceptionBuilder<? extends DittoRuntimeException>
newBuilder(DittoRuntimeException dittoRuntimeException)
Returns a new mutable builder with a fluent API for adittoRuntimeException
.protected static Optional<String>
readDescription(org.eclipse.ditto.json.JsonObject jsonObject)
protected static Optional<URI>
readHRef(org.eclipse.ditto.json.JsonObject jsonObject)
protected static String
readMessage(org.eclipse.ditto.json.JsonObject jsonObject)
DittoRuntimeException
setDittoHeaders(DittoHeaders dittoHeaders)
Sets theDittoHeaders
and returns a new object.org.eclipse.ditto.json.JsonObject
toJson()
Returns all non hidden marked fields of this exception.org.eclipse.ditto.json.JsonObject
toJson(JsonSchemaVersion schemaVersion, Predicate<org.eclipse.ditto.json.JsonField> thePredicate)
Returns this object asJsonValue
.String
toString()
-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.ditto.model.base.json.Jsonifiable
getLatestSchemaVersion, getSupportedSchemaVersions, implementsSchemaVersion, implementsSchemaVersion, toJsonString
-
Methods inherited from interface org.eclipse.ditto.model.base.json.Jsonifiable.WithPredicate
toJson, toJsonString, toJsonString
-
-
-
-
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 newDittoRuntimeException
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 withThrowable.getMessage()
.description
- a description with further information about the exception.cause
- the cause of the exception for later retrieval withThrowable.getCause()
.href
- a link to a resource which provides further information about the exception.- Throws:
NullPointerException
- iferrorCode
,statusCode
ordittoHeaders
isnull
.
-
-
Method Detail
-
getEmptyBuilder
protected DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> getEmptyBuilder()
Each subclass should override this method to provide an implementation ofDittoRuntimeExceptionBuilder
.Per default, an instance
DittoRuntimeException.Builder
is used, which builds a genericDittoRuntimeException
.- Returns:
- A builder to construct a DittoRuntimeException.
-
getBuilder
public DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> getBuilder()
Construct a builderb
such thatb.build()
has identical class and fields asthis
.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 aExecutionException
, 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 DittoRuntimeException.Builder newBuilder(String errorCode, HttpStatusCode statusCode)
Returns a new mutable builder for fluently creating instances ofDittoRuntimeException
s..- Parameters:
errorCode
- a code which uniquely identifies the exception.statusCode
- the HTTP status code.- Returns:
- the new builder.
- Throws:
NullPointerException
- if any argument isnull
.IllegalArgumentException
- iferrorCode
is empty.
-
newBuilder
public static DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> newBuilder(DittoRuntimeException dittoRuntimeException)
Returns a new mutable builder with a fluent API for adittoRuntimeException
. 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
- ifdittoRuntimeException
isnull
.
-
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.
-
getDittoHeaders
public DittoHeaders getDittoHeaders()
Description copied from interface:WithDittoHeaders
Returns theDittoHeaders
which are associated with this object.- Specified by:
getDittoHeaders
in interfaceWithDittoHeaders<DittoRuntimeException>
- Returns:
- the DittoHeaders of this object.
-
setDittoHeaders
public DittoRuntimeException setDittoHeaders(DittoHeaders dittoHeaders)
Description copied from interface:WithDittoHeaders
Sets theDittoHeaders
and returns a new object.- Specified by:
setDittoHeaders
in interfaceWithDittoHeaders<DittoRuntimeException>
- Parameters:
dittoHeaders
- the DittoHeaders to set.- Returns:
- the newly created object with the set DittoHeaders.
-
getImplementedSchemaVersion
public JsonSchemaVersion getImplementedSchemaVersion()
Description copied from interface:Jsonifiable
Returns the JsonSchemaVersion the instance of this Jsonifiable implements. Must be overridden if schema version is persisted in implementing entity itself! Otherwise falls back to theJsonifiable.getLatestSchemaVersion()
.- Specified by:
getImplementedSchemaVersion
in interfaceJsonifiable<org.eclipse.ditto.json.JsonObject>
- Returns:
- the current JsonSchemaVersion.
-
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.
-
getManifest
public String getManifest()
Description copied from interface:WithManifest
Returns the manifest (type hint).- Specified by:
getManifest
in interfaceWithManifest
- Returns:
- the manifest.
-
toJson
public org.eclipse.ditto.json.JsonObject toJson()
Returns all non hidden marked fields of this exception.- Specified by:
toJson
in interfaceJsonifiable<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 asJsonValue
. The content of the result is determined by the given predicate.- Specified by:
toJson
in interfaceJsonifiable.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 passedjsonObjectBuilder
.- 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.
-
-