Skip to content

Commit c886206

Browse files
carlossgAdrian Cole
authored andcommitted
Handle invalid HTTP received from server
If response was empty it caused a NPE
1 parent 9caeff8 commit c886206

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎core/src/main/java/feign/Client.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package feign;
1717

18+
import static java.lang.String.format;
19+
1820
import java.io.IOException;
1921
import java.io.InputStream;
2022
import java.io.OutputStream;
@@ -150,6 +152,12 @@ Response convertResponse(HttpURLConnection connection) throws IOException {
150152
int status = connection.getResponseCode();
151153
String reason = connection.getResponseMessage();
152154

155+
if (status < 0 || reason == null) {
156+
// invalid response
157+
throw new IOException(format("Invalid HTTP executing %s %s", connection.getRequestMethod(),
158+
connection.getURL()));
159+
}
160+
153161
Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>();
154162
for (Map.Entry<String, List<String>> field : connection.getHeaderFields().entrySet()) {
155163
// response message

0 commit comments

Comments
 (0)