Will Apache HttpClient succeed in throwing an IOException on all HTTP 5XX HTTP errors?

Apache HttpClient docs for the method execute(HttpHost target, HttpRequest request)say:

IOException - in case of a problem or the connection was interrupted

If I catch an IOException, will it catch ALL 5xx Server Errors ?

try {
  response = client.execute(httpHost, request);
} catch (IOException e) {
  // throw custom Exception
} finally {
  // close response and client
}

The reason I ask is because after this logic somewhere else down the line we do something like the following:

if (response.getStatusLine().getStatusCode() >= 500) {
  // Could we ever reach this point after the code above?
}
+4
source share
1 answer

No, HttpClient will not throw an IO exception for any 500 / 5xx response .

IOException (, , ) TCP-, (, ).

"HTTP 500" - - - . , , 200.

, "[] "; , .

+10

Source: https://habr.com/ru/post/1606224/


All Articles