@@ -38,6 +38,10 @@ private QosException(String message) {
3838 super (message );
3939 }
4040
41+ private QosException (String message , Throwable cause ) {
42+ super (message , cause );
43+ }
44+
4145 public abstract <T > T accept (Visitor <T > visitor );
4246
4347 public interface Visitor <T > {
@@ -56,6 +60,13 @@ public static Throttle throttle() {
5660 return new Throttle (Optional .empty ());
5761 }
5862
63+ /**
64+ * Like {@link #throttle()}, but includes a cause.
65+ */
66+ public static Throttle throttle (Throwable cause ) {
67+ return new Throttle (Optional .empty (), cause );
68+ }
69+
5970 /**
6071 * Like {@link #throttle()}, but additionally requests that the client wait for at least the given duration before
6172 * retrying the request.
@@ -64,6 +75,13 @@ public static Throttle throttle(Duration duration) {
6475 return new Throttle (Optional .of (duration ));
6576 }
6677
78+ /**
79+ * Like {@link #throttle(Duration)}, but includes a cause.
80+ */
81+ public static Throttle throttle (Duration duration , Throwable cause ) {
82+ return new Throttle (Optional .of (duration ), cause );
83+ }
84+
6785 /**
6886 * Returns a {@link RetryOther} exception indicating that the calling client should retry against the given node of
6987 * this service.
@@ -72,6 +90,13 @@ public static RetryOther retryOther(URL redirectTo) {
7290 return new RetryOther (redirectTo );
7391 }
7492
93+ /**
94+ * Like {@link #retryOther(URL)}, but includes a cause.
95+ */
96+ public static RetryOther retryOther (URL redirectTo , Throwable cause ) {
97+ return new RetryOther (redirectTo , cause );
98+ }
99+
75100 /**
76101 * An exception indicating that (this node of) this service is currently unavailable and the client may try again at
77102 * a later time, possibly against a different node of this service.
@@ -80,6 +105,13 @@ public static Unavailable unavailable() {
80105 return new Unavailable ();
81106 }
82107
108+ /**
109+ * Like {@link #unavailable()}, but includes a cause.
110+ */
111+ public static Unavailable unavailable (Throwable cause ) {
112+ return new Unavailable (cause );
113+ }
114+
83115 /** See {@link #throttle}. */
84116 public static final class Throttle extends QosException {
85117 private final Optional <Duration > retryAfter ;
@@ -89,6 +121,11 @@ private Throttle(Optional<Duration> retryAfter) {
89121 this .retryAfter = retryAfter ;
90122 }
91123
124+ private Throttle (Optional <Duration > retryAfter , Throwable cause ) {
125+ super ("Suggesting request throttling with optional retryAfter duration: " + retryAfter , cause );
126+ this .retryAfter = retryAfter ;
127+ }
128+
92129 public Optional <Duration > getRetryAfter () {
93130 return retryAfter ;
94131 }
@@ -108,6 +145,11 @@ private RetryOther(URL redirectTo) {
108145 this .redirectTo = redirectTo ;
109146 }
110147
148+ private RetryOther (URL redirectTo , Throwable cause ) {
149+ super ("Suggesting request retry against: " + redirectTo .toString (), cause );
150+ this .redirectTo = redirectTo ;
151+ }
152+
111153 /** Indicates an alternative URL of this service against which the request may be retried. */
112154 public URL getRedirectTo () {
113155 return redirectTo ;
@@ -137,6 +179,10 @@ private Unavailable() {
137179 super ("Server unavailable" );
138180 }
139181
182+ private Unavailable (Throwable cause ) {
183+ super ("Server unavailable" , cause );
184+ }
185+
140186 @ Override
141187 public <T > T accept (Visitor <T > visitor ) {
142188 return visitor .visit (this );
0 commit comments