Usually I used to check for the server different code responses in my RestClient class using the org.apache.http.HttpStatus class as the following
you can cast the returned value of openConnection to HttpURLConnection, and use getResponseCode() to retrieve response code
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
final int responseCode = urlConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
} else if (responseCode == HttpURLConnection.HTTP_BAD_GATEWAY) {
}
HttpURLConnection.getResponseCode() documentation is here