.anyMatch(series -> statusCode.series().equals(series));
private boolean httpStatusSuccessful(HttpServletResponse response) { if (response.getStatus() == 0) { return false; } HttpStatus.Series httpStatusSeries = HttpStatus.Series .valueOf(response.getStatus()); return httpStatusSeries == HttpStatus.Series.SUCCESSFUL || httpStatusSeries == HttpStatus.Series.REDIRECTION; }
/** * Resolve the given status code to an {@code HttpStatus.Series}, if possible. * @param statusCode the HTTP status code (potentially non-standard) * @return the corresponding {@code Series}, or {@code null} if not found * @since 5.1.3 */ @Nullable public static Series resolve(int statusCode) { int seriesCode = statusCode / 100; for (Series series : values()) { if (series.value == seriesCode) { return series; } } return null; } }
public void handleError(final ClientHttpResponse response) throws IOException { if (!HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series())) {
HttpResponse response = httpClient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); if (HttpStatus.valueOf(statusLine.getStatusCode()).series().equals(Series.SUCCESSFUL)) { HttpEntity entity = response.getEntity(); try (InputStream is = entity.getContent()) {
@Override public void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException { if (statusCode.series() == HttpStatus.Series.CLIENT_ERROR) { throw new HttpClientErrorException(statusCode, response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response)); } else if (statusCode.series() == HttpStatus.Series.SERVER_ERROR) { throw new HttpServerErrorException(statusCode, response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response)); } else { try { HttpStatus.Series.valueOf(statusCode); super.handleError(response, statusCode); } catch (Exception e) { throw new UnknownHttpStatusCodeException(statusCode.value(), response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response)); } } }
/** * Resolve the given status code to an {@code HttpStatus.Series}, if possible. * @param statusCode the HTTP status code (potentially non-standard) * @return the corresponding {@code Series}, or {@code null} if not found * @since 5.1.3 */ @Nullable public static Series resolve(int statusCode) { int seriesCode = statusCode / 100; for (Series series : values()) { if (series.value == seriesCode) { return series; } } return null; } }
/** * Return the enum constant of this type with the corresponding series. * @param statusCode the HTTP status code (potentially non-standard) * @return the enum constant of this type with the corresponding series * @throws IllegalArgumentException if this enum has no corresponding constant */ public static Series valueOf(int statusCode) { int seriesCode = statusCode / 100; for (Series series : values()) { if (series.value == seriesCode) { return series; } } throw new IllegalArgumentException("No matching constant for [" + statusCode + "]"); } }
/** * Template method called from {@link #hasError(ClientHttpResponse)}. * <p>The default implementation checks if the given status code is * {@code HttpStatus.Series#CLIENT_ERROR CLIENT_ERROR} or * {@code HttpStatus.Series#SERVER_ERROR SERVER_ERROR}. * Can be overridden in subclasses. * @param unknownStatusCode the HTTP status code as raw value * @return {@code true} if the response indicates an error; {@code false} otherwise * @since 4.3.21 * @see HttpStatus.Series#CLIENT_ERROR * @see HttpStatus.Series#SERVER_ERROR */ protected boolean hasError(int unknownStatusCode) { HttpStatus.Series series = HttpStatus.Series.resolve(unknownStatusCode); return (series == HttpStatus.Series.CLIENT_ERROR || series == HttpStatus.Series.SERVER_ERROR); }
/** * Return the enum constant of this type with the corresponding series. * @param statusCode the HTTP status code (potentially non-standard) * @return the enum constant of this type with the corresponding series * @throws IllegalArgumentException if this enum has no corresponding constant */ public static Series valueOf(int statusCode) { Series series = resolve(statusCode); if (series == null) { throw new IllegalArgumentException("No matching constant for [" + statusCode + "]"); } return series; }
/** * Return the enum constant of this type with the corresponding series. * @param status a standard HTTP status enum value * @return the enum constant of this type with the corresponding series * @throws IllegalArgumentException if this enum has no corresponding constant */ public static Series valueOf(HttpStatus status) { return valueOf(status.value); }
/** * Return the HTTP status series of this status code. * @see HttpStatus.Series */ public Series series() { return Series.valueOf(this); }
public boolean hasError(ClientHttpResponse response) throws IOException { return HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series()) || this.errorHandler.hasError(response); }
/** * Return the enum constant of this type with the corresponding series. * @param status a standard HTTP status enum value * @return the enum constant of this type with the corresponding series * @throws IllegalArgumentException if this enum has no corresponding constant */ public static Series valueOf(HttpStatus status) { return valueOf(status.value); }
/** * Return the HTTP status series of this status code. * @see HttpStatus.Series */ public Series series() { return Series.valueOf(this); }
@Override public void handleError(ClientHttpResponse response) throws IOException { if (HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series())) { Map<String, Object> errorDetails = extractErrorDetailsFromResponse(response); throw new UncategorizedApiException("wechat", errorDetails.containsKey("errmsg") ? (String) errorDetails.get("errmsg") : "Unknown error", null); } handleUncategorizedError(response); }
private boolean httpStatusSuccessful(HttpServletResponse response) { if (response.getStatus() == 0) { return false; } HttpStatus.Series httpStatusSeries = HttpStatus.Series .valueOf(response.getStatus()); return httpStatusSeries == HttpStatus.Series.SUCCESSFUL || httpStatusSeries == HttpStatus.Series.REDIRECTION; }