/** * Constructs a new {@code AclInvalidException} object with the given exception message. * * @param message detail message. This message can be later retrieved by the {@link #getMessage()} method. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new AclInvalidException. */ public static AclInvalidException fromMessage(final String message, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(message) .build(); }
@Override public DittoRuntimeException setDittoHeaders(final DittoHeaders dittoHeaders) { return newBuilder(this).dittoHeaders(dittoHeaders).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(); }
/** * Sets the cause which led to the exception to be built. * * @param causeSupplier supplier of the cause to be set. * @return this builder to allow method chaining. * @throws NullPointerException if {@code messageSupplier} is {@code null}. */ public DittoRuntimeExceptionBuilder<T> cause(final Supplier<Throwable> causeSupplier) { checkSupplier(causeSupplier); return cause(causeSupplier.get()); }
/** * Sets the detail message of the exception to be built. * * @param messageSupplier supplier of the message to be set. * @return this builder to allow method chaining. * @throws NullPointerException if {@code messageSupplier} is {@code null}. */ public DittoRuntimeExceptionBuilder<T> message(final Supplier<String> messageSupplier) { checkSupplier(messageSupplier); return message(messageSupplier.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()); }
@Override protected PolicyTooLargeException newInvalidSizeException(final long maxSize, final long actualSize, final DittoHeaders headers) { return PolicyTooLargeException.newBuilder(actualSize, maxSize).dittoHeaders(headers).build(); }
private void setOptions(final String options, final QueryBuilder queryBuilder, final DittoHeaders dittoHeaders) { try { final ParameterOptionVisitor visitor = new ParameterOptionVisitor(fieldExpressionFactory, queryBuilder); visitor.visitAll(rqlOptionParser.parse(options)); } catch (final ParserException | IllegalArgumentException e) { throw InvalidOptionException.newBuilder() .message(e.getMessage()) .cause(e) .dittoHeaders(dittoHeaders) .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)); }
private void validateEntityTagMatcher(final String key, @Nullable final CharSequence charSequence) { final String headerValue = String.valueOf(charSequence); if (!EntityTagMatcher.isValid(headerValue)) { final DittoRuntimeExceptionBuilder<DittoHeaderInvalidException> exceptionBuilder = DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "entity-tag"); try { exceptionBuilder.href(new URI(RFC_7232_SECTION_2_3)); } catch (final URISyntaxException e) { // Do nothing. If this happens, there is no href appended to the exception builder. } throw exceptionBuilder.build(); } }
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); }
/** * 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); }
/** * Sets a link to a resource which provides further information about the exception to be built. * * @param hrefSupplier supplier of the link to be set. * @return this builder to allow method chaining. * @throws NullPointerException if {@code messageSupplier} is {@code null}. */ public DittoRuntimeExceptionBuilder<T> href(final Supplier<URI> hrefSupplier) { checkSupplier(hrefSupplier); return href(hrefSupplier.get()); }
@Override public Builder cause(@Nullable final Throwable cause) { if (cause == null) { message(DEFAULT_MESSAGE); } else { super.cause(cause); message(MessageFormat.format(MESSAGE_TEMPLATE, cause.getMessage())); } return this; }
static DittoRuntimeException attributesNotFound(final String thingId, final DittoHeaders dittoHeaders) { return AttributesNotAccessibleException.newBuilder(thingId) .dittoHeaders(dittoHeaders) .build(); }
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); }
/** * 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 the detail message of the exception to be built. * * @param messageSupplier supplier of the message to be set. * @return this builder to allow method chaining. * @throws NullPointerException if {@code messageSupplier} is {@code null}. */ public DittoRuntimeExceptionBuilder<T> message(final Supplier<String> messageSupplier) { checkSupplier(messageSupplier); return message(messageSupplier.get()); }