(Response response)
| 481 | } |
| 482 | |
| 483 | private Response checkError(Response response) throws ChainException { |
| 484 | String rid = response.headers().get("Chain-Request-ID"); |
| 485 | if (rid == null || rid.length() == 0) { |
| 486 | // Header field Chain-Request-ID is set by the backend |
| 487 | // API server. If this field is set, then we can expect |
| 488 | // the body to be well-formed JSON. If it's not set, |
| 489 | // then we are probably talking to a gateway or proxy. |
| 490 | throw new ConnectivityException(response); |
| 491 | } |
| 492 | |
| 493 | if ((response.code() / 100) != 2) { |
| 494 | try { |
| 495 | APIException err = |
| 496 | Utils.serializer.fromJson(response.body().charStream(), APIException.class); |
| 497 | if (err.code != null) { |
| 498 | err.requestId = rid; |
| 499 | err.statusCode = response.code(); |
| 500 | throw err; |
| 501 | } |
| 502 | } catch (IOException ex) { |
| 503 | throw new JSONException("Unable to read body. " + ex.getMessage(), rid); |
| 504 | } |
| 505 | } |
| 506 | return response; |
| 507 | } |
| 508 | |
| 509 | private void nextURL(int failedIndex) { |
| 510 | if (this.urls.size() == 1) { |
no test coverage detected