Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(retrofit): move url attribute from SpinnakerHttpException to SpinnakerServerException #1110

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,28 @@
/** Wraps an exception converting a successful retrofit http response body to its indicated type */
public class SpinnakerConversionException extends SpinnakerServerException {

/**
* Construct a SpinnakerServerException from retrofit2 with a message and cause (e.g. an exception
* converting a response to the specified type).
*/
public SpinnakerConversionException(String message, Throwable cause, Request request) {
super(message, cause, request);
setRetryable(false);
}

/**
* Construct a SpinnakerConversionException from another SpinnakerConversionException (e.g. via
* newInstance).
*/
public SpinnakerConversionException(String message, SpinnakerConversionException cause) {
super(message, cause);
setRetryable(false);
}

/** Construct a SpinnakerConversionException corresponding to a RetrofitError. */
public SpinnakerConversionException(RetrofitError e) {
super(e);
setRetryable(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, that sucks we need to add the false everywhere. May be nice to have a implements NonRetryableException or something like that, but that is separate from this PR

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class SpinnakerHttpException extends SpinnakerServerException {
*/
private final String reason;

/** Construct a SpinnakerHttpException corresponding to a RetrofitError. */
public SpinnakerHttpException(RetrofitError e) {
super(e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,27 @@
import okhttp3.Request;
import retrofit.RetrofitError;

/** Wraps an exception of kind {@link RetrofitError.Kind} NETWORK. */
/** Represents a network error while attempting to execute a retrofit http client request. */
@NonnullByDefault
public final class SpinnakerNetworkException extends SpinnakerServerException {

/**
* Construct a SpinnakerNetworkException from retrofit2 with a cause (e.g. an exception sending a
* request or processing a response).
*/
public SpinnakerNetworkException(Throwable cause, Request request) {
super(cause, request);
}

/**
* Construct a SpinnakerNetworkException from another SpinnakerNetworkException (e.g. via
* newInstance).
*/
public SpinnakerNetworkException(String message, SpinnakerNetworkException cause) {
super(message, cause);
}

/** Construct a SpinnakerNetworkException corresponding to a RetrofitError. */
public SpinnakerNetworkException(RetrofitError e) {
super(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,43 @@ public class SpinnakerServerException extends SpinnakerException {

private final String url;
dbyron-sf marked this conversation as resolved.
Show resolved Hide resolved

/** Construct a SpinnakerServerException corresponding to a RetrofitError. */
public SpinnakerServerException(RetrofitError e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then these go away and allows for only the SpinnakerHttpException to utilize all the retrofit fields

super(e.getMessage(), e.getCause());
url = e.getUrl();
}

/**
* Construct a SpinnakerServerException from retrofit2 with no cause (e.g. a non-200 http
* response).
*/
public SpinnakerServerException(Request request) {
super();
url = request.url().toString();
}

/**
* Construct a SpinnakerServerException from retrofit2 with a cause (e.g. an exception sending a
* request or processing a response).
*/
public SpinnakerServerException(Throwable cause, Request request) {
super(cause);
this.url = request.url().toString();
}

/**
* Construct a SpinnakerServerException from retrofit2 with a message and cause (e.g. an exception
* converting a response to the specified type).
*/
public SpinnakerServerException(String message, Throwable cause, Request request) {
super(message, cause);
this.url = request.url().toString();
}

/**
* Construct a SpinnakerServerException from another SpinnakerServerException (e.g. via
* newInstance).
*/
public SpinnakerServerException(String message, SpinnakerServerException cause) {
super(message, cause);
this.url = cause.getUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ void testSpinnakerConversionException() {
SpinnakerConversionException spinnakerConversionException =
catchThrowableOfType(
() -> retrofit2Service.getRetrofit2().execute(), SpinnakerConversionException.class);
assertThat(spinnakerConversionException.getRetryable()).isNotNull();
assertThat(spinnakerConversionException.getRetryable()).isFalse();
assertThat(spinnakerConversionException).hasMessage("Failed to process response body");
assertThat(spinnakerConversionException.getUrl())
.isEqualTo(mockWebServer.url("/retrofit2").toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ void testSpinnakerConversionException() {

SpinnakerConversionException spinnakerConversionException =
catchThrowableOfType(() -> retrofitService.getData(), SpinnakerConversionException.class);
assertThat(spinnakerConversionException.getRetryable()).isNotNull();
assertThat(spinnakerConversionException.getRetryable()).isFalse();
assertThat(spinnakerConversionException)
.hasMessageContaining("Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $");
assertThat(spinnakerConversionException.getUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ void testSpinnakerConversionException_NewInstance() {
assertThat(newException).hasCause(e);
SpinnakerConversionException spinnakerConversionException =
(SpinnakerConversionException) newException;
assertThat(spinnakerConversionException.getRetryable()).isNotNull();
assertThat(spinnakerConversionException.getRetryable()).isFalse();
assertThat(spinnakerConversionException.getUrl()).isEqualTo(url);
}
}
Expand Down