Skip to content

Commit

Permalink
fix(exceptions): Exception message should never be empty (spinnaker#991
Browse files Browse the repository at this point in the history
…) (spinnaker#79)

When socket timeouts occur the response body is null which results in an
empty message being sent back to deck which is not useful.

Signed-off-by: benjamin_j_powell <[email protected]>

Signed-off-by: benjamin_j_powell <[email protected]>
Co-authored-by: benjamin_j_powell <[email protected]>

Co-authored-by: xibz <[email protected]>
Co-authored-by: benjamin_j_powell <[email protected]>
  • Loading branch information
3 people authored and GitHub Enterprise committed Apr 5, 2023
1 parent b04c96e commit 096381b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public SpinnakerServerException(RetrofitError e) {
RetrofitErrorResponseBody body =
(RetrofitErrorResponseBody) e.getBodyAs(RetrofitErrorResponseBody.class);
this.rawMessage =
Optional.ofNullable(body).map(RetrofitErrorResponseBody::getMessage).orElse("");
Optional.ofNullable(body).map(RetrofitErrorResponseBody::getMessage).orElse(e.getMessage());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.junit.Assert;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -35,6 +37,7 @@
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.http.HttpStatus;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import retrofit.converter.JacksonConverter;
import retrofit.http.GET;
Expand Down Expand Up @@ -146,6 +149,16 @@ public void testOtherClientErrorHasNullRetryable() {
assertNull(spinnakerHttpException.getRetryable());
}

@Test
public void testSimpleSpinnakerNetworkException() {
String message = "my custom message";
IOException e = new IOException(message);
RetrofitError retrofitError = RetrofitError.networkError("http://localhost", e);
SpinnakerRetrofitErrorHandler handler = SpinnakerRetrofitErrorHandler.getInstance();
Throwable throwable = handler.handleError(retrofitError);
Assert.assertEquals(message, throwable.getMessage());
}

interface RetrofitService {
@GET("/foo")
Response getFoo();
Expand Down

0 comments on commit 096381b

Please sign in to comment.