@@ -70,7 +70,7 @@ public Response intercept(@NotNull Chain chain) throws IOException {
7070 String .format (
7171 Locale .getDefault (), "httpCode=%d %s" , response .code (), response .message ());
7272 if (!shouldRetryHttpErrorCode (response .code ())) {
73- return response ;
73+ return getReturnResp ( chain , response , "nullcheck: shouldRetryHttpErrorCode is false" ) ;
7474 }
7575 } else if (tryCount > 1 ) {
7676 log .info (
@@ -83,7 +83,7 @@ public Response intercept(@NotNull Chain chain) throws IOException {
8383 response = makeErrorResp (chain , msg );
8484 successful = false ;
8585 if (!shouldRetryException (ex )) {
86- return response ;
86+ return getReturnResp ( chain , response , "nullcheck: shouldRetryException is false" ) ;
8787 }
8888 }
8989
@@ -110,7 +110,8 @@ public Response intercept(@NotNull Chain chain) throws IOException {
110110 tryCount ,
111111 chain .request ().url (),
112112 msg );
113- return response ; // Exit without further retries
113+ return getReturnResp (
114+ chain , response , "nullcheck: isShuttingDown is true" ); // Exit without further retries
114115 }
115116
116117 log .warn (
@@ -134,7 +135,21 @@ public Response intercept(@NotNull Chain chain) throws IOException {
134135 tryCount ++;
135136 } while (!successful && (retryForever || tryCount <= maxTryCount ) && !isShuttingDown .get ());
136137
137- return response ;
138+ return getReturnResp (
139+ chain ,
140+ response ,
141+ String .format (
142+ "nullcheck: exit loop successful=%s, retryForever=%s tryCount=%d maxTryCount=%d shutdown=%s" ,
143+ successful , retryForever , tryCount , maxTryCount , isShuttingDown .get ()));
144+ }
145+
146+ // interceptor should never return null, create dummy resp and embed an error msg if it does
147+ private Response getReturnResp (Chain chain , Response resp , String msg ) {
148+ if (resp != null ) {
149+ return resp ;
150+ }
151+
152+ return makeErrorResp (chain , String .format (msg , "%s url: %s" , chain .request ().url ()));
138153 }
139154
140155 int getRetryAfterHeaderInSeconds (Response response ) {
0 commit comments