Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-591.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: feature
feature:
description: '`QosException` can now be created with a cause.'
links:
- https://github.com/palantir/conjure-java-runtime-api/pull/591
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ private QosException(String message) {
super(message);
}

private QosException(String message, Throwable cause) {
super(message, cause);
}

public abstract <T> T accept(Visitor<T> visitor);

public interface Visitor<T> {
Expand All @@ -56,6 +60,13 @@ public static Throttle throttle() {
return new Throttle(Optional.empty());
}

/**
* Like {@link #throttle()}, but includes a cause.
*/
public static Throttle throttle(Throwable cause) {
return new Throttle(Optional.empty(), cause);
}

/**
* Like {@link #throttle()}, but additionally requests that the client wait for at least the given duration before
* retrying the request.
Expand All @@ -64,6 +75,13 @@ public static Throttle throttle(Duration duration) {
return new Throttle(Optional.of(duration));
}

/**
* Like {@link #throttle(Duration)}, but includes a cause.
*/
public static Throttle throttle(Duration duration, Throwable cause) {
return new Throttle(Optional.of(duration), cause);
}

/**
* Returns a {@link RetryOther} exception indicating that the calling client should retry against the given node of
* this service.
Expand All @@ -72,6 +90,13 @@ public static RetryOther retryOther(URL redirectTo) {
return new RetryOther(redirectTo);
}

/**
* Like {@link #retryOther(URL)}, but includes a cause.
*/
public static RetryOther retryOther(URL redirectTo, Throwable cause) {
return new RetryOther(redirectTo, cause);
}

/**
* An exception indicating that (this node of) this service is currently unavailable and the client may try again at
* a later time, possibly against a different node of this service.
Expand All @@ -80,6 +105,13 @@ public static Unavailable unavailable() {
return new Unavailable();
}

/**
* Like {@link #unavailable()}, but includes a cause.
*/
public static Unavailable unavailable(Throwable cause) {
return new Unavailable(cause);
}

/** See {@link #throttle}. */
public static final class Throttle extends QosException {
private final Optional<Duration> retryAfter;
Expand All @@ -89,6 +121,11 @@ private Throttle(Optional<Duration> retryAfter) {
this.retryAfter = retryAfter;
}

private Throttle(Optional<Duration> retryAfter, Throwable cause) {
super("Suggesting request throttling with optional retryAfter duration: " + retryAfter, cause);
this.retryAfter = retryAfter;
}

public Optional<Duration> getRetryAfter() {
return retryAfter;
}
Expand All @@ -108,6 +145,11 @@ private RetryOther(URL redirectTo) {
this.redirectTo = redirectTo;
}

private RetryOther(URL redirectTo, Throwable cause) {
super("Suggesting request retry against: " + redirectTo.toString(), cause);
this.redirectTo = redirectTo;
}

/** Indicates an alternative URL of this service against which the request may be retried. */
public URL getRedirectTo() {
return redirectTo;
Expand Down Expand Up @@ -137,6 +179,10 @@ private Unavailable() {
super("Server unavailable");
}

private Unavailable(Throwable cause) {
super("Server unavailable", cause);
}

@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this);
Expand Down