/** * Sets a description with further information about the exception to be built. * * @param descriptionSupplier supplier of the description to be set. * @return this builder to allow method chaining. * @throws NullPointerException if {@code messageSupplier} is {@code null}. */ public DittoRuntimeExceptionBuilder<T> description(final Supplier<String> descriptionSupplier) { checkSupplier(descriptionSupplier); return description(descriptionSupplier.get()); }
/** * Sets a description with further information about the exception to be built. * * @param descriptionSupplier supplier of the description to be set. * @return this builder to allow method chaining. * @throws NullPointerException if {@code messageSupplier} is {@code null}. */ public DittoRuntimeExceptionBuilder<T> description(final Supplier<String> descriptionSupplier) { checkSupplier(descriptionSupplier); return description(descriptionSupplier.get()); }
private ConnectionFailedException buildConnectionFailedException(final Map<String, Exception> failedSources) { return ConnectionFailedException .newBuilder(connection.getId()) .message("Failed to consume sources: " + failedSources.keySet()) .description(() -> failedSources.entrySet() .stream() .map(e -> e.getKey() + ": " + e.getValue().getMessage()) .collect(Collectors.joining(", "))) .build(); }
private ConnectionFailedException buildConnectionFailedException(final Map<String, Exception> failedSources) { return ConnectionFailedException .newBuilder(connection.getId()) .message("Failed to consume sources: " + failedSources.keySet()) .description(() -> failedSources.entrySet() .stream() .map(e -> e.getKey() + ": " + e.getValue().getMessage()) .collect(Collectors.joining(", "))) .build(); }
/** * Create a builder of this exception. * * @param namespace the namespace being blocked. * @return a builder of this exception with default message. */ public static DittoRuntimeExceptionBuilder<NamespaceBlockedException> newBuilder(final String namespace) { return new Builder() .message(MessageFormat.format(MESSAGE_TEMPLATE, namespace)) .description(DEFAULT_DESCRIPTION); }
private DittoRuntimeExceptionBuilder<ConnectionUnavailableException> fatalError(final String whatHappened) { return ConnectionUnavailableException.newBuilder("unimportant") .message(String.format("Fatal error: %s.", whatHappened)) .description("Please contact the service team.") .dittoHeaders(dittoHeaders); }
private DittoRuntimeExceptionBuilder<ConnectionUnavailableException> fatalError(final String whatHappened) { return ConnectionUnavailableException.newBuilder("unimportant") .message(String.format("Fatal error: %s.", whatHappened)) .description("Please contact the service team.") .dittoHeaders(dittoHeaders); }
/** * Constructs a new {@code ConnectionFailedException} object with given message. * * @param message detail message. This message can be later retrieved by the {@link #getMessage()} method. * @param description error description, may be @{@code null}. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new ConnectionFailedException. */ public static ConnectionFailedException from(final String message, @Nullable final String description, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(message) .description(description) .build(); }
/** * Constructs a new {@code ConnectionFailedException} object with given message. * * @param message detail message. This message can be later retrieved by the {@link #getMessage()} method. * @param description error description, may be @{@code null}. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new ConnectionFailedException. */ public static ConnectionFailedException from(final String message, @Nullable final String description, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(message) .description(description) .build(); }
/** * Deserialize from JSON. * * @param jsonObject This exception in JSON format. * @param dittoHeaders Ditto headers. * @return Deserialized exception. */ public static NamespaceBlockedException fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { // deserialize message and description for delivery to client. return new Builder() .dittoHeaders(dittoHeaders) .message(jsonObject.getValue(JsonFields.MESSAGE).orElse(DEFAULT_MESSAGE)) .description(jsonObject.getValue(JsonFields.DESCRIPTION).orElse(DEFAULT_DESCRIPTION)) .build(); }
/** * Constructs a new {@code ThingIdInvalidException} object with the exception message extracted from the * given JSON object. * * @param jsonObject the JSON to read the {@link JsonFields#MESSAGE} field from. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new ThingIdInvalidException. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link JsonFields#MESSAGE} field. */ public static ThingIdInvalidException fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(readMessage(jsonObject)) .description(readDescription(jsonObject).orElse(DEFAULT_DESCRIPTION)) .href(readHRef(jsonObject).orElse(null)) .build(); }
/** * Constructs a new {@code AclInvalidException} object with the exception message extracted from the given JSON * object. * * @param jsonObject the JSON to read the {@link JsonFields#MESSAGE} field from. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new AclInvalidException. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link JsonFields#MESSAGE} field. */ public static AclInvalidException fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(readMessage(jsonObject)) .description(readDescription(jsonObject).orElse(DEFAULT_DESCRIPTION)) .href(readHRef(jsonObject).orElse(null)) .build(); }
/** * Constructs a new {@link PolicyInvalidException} object from the given JSON object. * * @param jsonObject the JSON to read the {@link JsonFields#MESSAGE} field from. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new {@link PolicyInvalidException}. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link * JsonFields#MESSAGE} field. */ public static PolicyInvalidException fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(readMessage(jsonObject)) .description(readDescription(jsonObject).orElse(DESCRIPTION_TEMPLATE)) .href(readHRef(jsonObject).orElse(null)) .build(); }
/** * Returns a mutable builder for this exception. * * @return the builder. */ public DittoRuntimeExceptionBuilder<NamespaceBlockedException> toBuilder() { return new Builder() .dittoHeaders(getDittoHeaders()) .message(getMessage()) .description(getDescription().orElse(DEFAULT_DESCRIPTION)) .cause(getCause()) .href(getHref().orElse(null)); }
/** * Deserialize from a JSON object. * * @param jsonObject the JSON object to deserialize. * @param dittoHeaders the headers. * @return an instance of this class. * @throws NullPointerException if any argument is {@code null}. */ public static ThingTooLargeException fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new ThingTooLargeException.Builder() .loadJson(jsonObject) .dittoHeaders(dittoHeaders) .message(readMessage(jsonObject)) .description(readDescription(jsonObject).orElse(DEFAULT_DESCRIPTION)) .href(readHRef(jsonObject).orElse(null)) .build(); }
private static ConnectionFailedException newConnectionFailedException(final Connection connection, final DittoHeaders dittoHeaders) { return ConnectionFailedException .newBuilder(connection.getId()) .dittoHeaders(dittoHeaders) .description("Could not establish a connection on '" + connection.getHostname() + ":" + connection.getPort() + "'. Make sure the " + "endpoint is reachable and that no firewall prevents the connection.") .build(); }
private static ConnectionFailedException newConnectionFailedException(final Connection connection, final DittoHeaders dittoHeaders) { return ConnectionFailedException .newBuilder(connection.getId()) .dittoHeaders(dittoHeaders) .description("Could not establish a connection on '" + connection.getHostname() + ":" + connection.getPort() + "'. Make sure the " + "endpoint is reachable and that no firewall prevents the connection.") .build(); }
private static void validateEnforcementInput(final Enforcement enforcement, final Supplier<String> sourceDescription, final DittoHeaders dittoHeaders) { final SourceAddressPlaceholder sourceAddressPlaceholder = PlaceholderFactory.newSourceAddressPlaceholder(); try { EnforcementFactoryFactory .newEnforcementFilterFactory(enforcement, sourceAddressPlaceholder) .getFilter("dummyTopic"); } catch (final DittoRuntimeException e) { throw invalidValueForConfig(enforcement.getInput(), "input", sourceDescription.get()) .cause(e) .description(MessageFormat.format(ERROR_DESCRIPTION, enforcement.getInput(), sourceAddressPlaceholder.getSupportedNames())) .dittoHeaders(dittoHeaders) .build(); } }
/** * Construct a builder {@code b} such that {@code b.build()} has identical class and fields as {@code this}. * <p> * A subclass should extend this method if it adds another field. * * @return A builder to construct an identical copy of {@code this}. */ public DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> getBuilder() { return getEmptyBuilder() .dittoHeaders(dittoHeaders) .message(getMessage()) .cause(getCause()) .description(description) .href(href); }
/** * Construct a builder {@code b} such that {@code b.build()} has identical class and fields as {@code this}. * <p> * A subclass should extend this method if it adds another field. * * @return A builder to construct an identical copy of {@code this}. */ public DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> getBuilder() { return getEmptyBuilder() .dittoHeaders(dittoHeaders) .message(getMessage()) .cause(getCause()) .description(description) .href(href); }