/** * Whether this status code is in the HTTP series * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}. * This is a shortcut for checking the value of {@link #series()}. * @since 5.0 * @see #is4xxClientError() * @see #is5xxServerError() */ public boolean isError() { return (is4xxClientError() || is5xxServerError()); }
/** * Whether this status code is in the HTTP series * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}. * This is a shortcut for checking the value of {@link #series()}. * @since 5.0 * @see #is4xxClientError() * @see #is5xxServerError() */ public boolean isError() { return (is4xxClientError() || is5xxServerError()); }
@Override protected boolean hasError(HttpStatus statusCode) { return statusCode.is5xxServerError(); } });
@Override protected boolean hasError(HttpStatus statusCode) { return statusCode.is5xxServerError(); } };
@Override protected boolean hasError(HttpStatus statusCode) { return statusCode.is5xxServerError(); } });
private <T> Publisher<? extends T> readResponseBody(String logId, Request request, ClientResponse response, Class<T> responseType) { if (RawActionResponse.class.equals(responseType)) { ClientLogger.logRawResponse(logId, response.statusCode()); return Mono.just(responseType.cast(RawActionResponse.create(response))); } if (response.statusCode().is5xxServerError()) { ClientLogger.logRawResponse(logId, response.statusCode()); return handleServerError(request, response); } return response.body(BodyExtractors.toMono(byte[].class)) // .map(it -> new String(it, StandardCharsets.UTF_8)) // .doOnNext(it -> ClientLogger.logResponse(logId, response.statusCode(), it)) // .flatMap(content -> doDecode(response, responseType, content)); }
try { ResponseEntity<Boolean> res = restTemplate.postForEntity(url, notifyConnectParams,Boolean.class); if(res.getStatusCode().equals(HttpStatus.OK)||res.getStatusCode().is5xxServerError()) { log.info("manager auto refresh res->{}", res); }else{
void terminateSpan(@Nullable ClientResponse clientResponse, @Nullable Throwable throwable) { if (clientResponse == null || clientResponse.statusCode() == null) { if (log.isDebugEnabled()) { log.debug("No response was returned. Will close the span [" + this.span + "]"); } handleReceive(this.span, this.ws, clientResponse, throwable); return; } boolean error = clientResponse.statusCode().is4xxClientError() || clientResponse.statusCode().is5xxServerError(); if (error) { if (log.isDebugEnabled()) { log.debug( "Non positive status code was returned from the call. Will close the span [" + this.span + "]"); } throwable = new RestClientException("Status code of the response is [" + clientResponse.statusCode().value() + "] and the reason is [" + clientResponse.statusCode().getReasonPhrase() + "]"); } handleReceive(this.span, this.ws, clientResponse, throwable); }
@Test public void test500Errors() throws Exception { handler.setErrorAtLevel(HttpStatus.Series.SERVER_ERROR); for (HttpStatus status : HttpStatus.values()) { ClientHttpResponse response = responses.get(status); if (status.is5xxServerError()) { Assert.assertTrue(handler.hasError(response)); } else { Assert.assertFalse(handler.hasError(response)); } } }
@Test public void test400_500Errors() throws Exception { handler.setErrorAtLevel(HttpStatus.Series.CLIENT_ERROR); for (HttpStatus status : HttpStatus.values()) { ClientHttpResponse response = responses.get(status); if (status.is5xxServerError() || status.is4xxClientError()) { Assert.assertTrue(handler.hasError(response)); } else { Assert.assertFalse(handler.hasError(response)); } } }
/** * Whether this status code is in the HTTP series * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}. * This is a shortcut for checking the value of {@link #series()}. * @since 5.0 * @see #is4xxClientError() * @see #is5xxServerError() */ public boolean isError() { return (is4xxClientError() || is5xxServerError()); }
/** * Whether this status code is in the HTTP series * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}. * This is a shortcut for checking the value of {@link #series()}. * @since 5.0 * @see #is4xxClientError() * @see #is5xxServerError() */ public boolean isError() { return (is4xxClientError() || is5xxServerError()); }
public static void log( final Throwable throwable, final HttpStatus status) { if (status.is4xxClientError()) { LOG.warn("{}: {}", status.getReasonPhrase(), throwable.getMessage()); } else if (status.is5xxServerError()) { LOG.error(status.getReasonPhrase(), throwable); } }
default void log( @SuppressWarnings("UnusedParameters") final Throwable throwable, @SuppressWarnings("UnusedParameters") final Problem problem, @SuppressWarnings("UnusedParameters") final NativeWebRequest request, final HttpStatus status) { if (status.is4xxClientError()) { LOG.warn("{}: {}", status.getReasonPhrase(), throwable.getMessage()); } else if (status.is5xxServerError()) { LOG.error(status.getReasonPhrase(), throwable); } }
private <T extends Publisher<?>> T bodyToPublisher( BodyExtractor<T, ? super ClientHttpResponse> extractor, Function<WebClientException, T> errorFunction) { HttpStatus status = statusCode(); if (status.is4xxClientError() || status.is5xxServerError()) { WebClientException ex = new WebClientException( "ClientResponse has erroneous status code: " + status.value() + " " + status.getReasonPhrase()); return errorFunction.apply(ex); } else { return body(extractor); } }
private boolean isValidDhisHttpResponse( DhisHttpResponse dhisHttpResponse ) { if ( dhisHttpResponse == null || dhisHttpResponse.getResponse().isEmpty() ) { log.warn( "Dhis http response is null" ); return false; } if ( HttpStatus.valueOf( dhisHttpResponse.getStatusCode() ).is2xxSuccessful() ) { return true; } if ( HttpStatus.valueOf( dhisHttpResponse.getStatusCode() ).is4xxClientError() ) { StringBuilder clientErrorMessage = buildErrorMessage( "Client Error. ", dhisHttpResponse ); log.warn( clientErrorMessage.toString() ); throw new MetadataVersionServiceException( clientErrorMessage.toString() ); } if ( HttpStatus.valueOf( dhisHttpResponse.getStatusCode() ).is5xxServerError() ) { StringBuilder serverErrorMessage = buildErrorMessage( "Server Error. ", dhisHttpResponse ); log.warn( serverErrorMessage.toString() ); throw new MetadataVersionServiceException( serverErrorMessage.toString() ); } return false; }
if (response.getStatusCode().is5xxServerError()) { throw new HttpServerErrorException(response.getStatusCode());
void terminateSpan(@Nullable ClientResponse clientResponse, @Nullable Throwable throwable) { if (clientResponse == null || clientResponse.statusCode() == null) { if (log.isDebugEnabled()) { log.debug("No response was returned. Will close the span [" + this.span + "]"); } handleReceive(this.span, this.ws, clientResponse, throwable); return; } boolean error = clientResponse.statusCode().is4xxClientError() || clientResponse.statusCode().is5xxServerError(); if (error) { if (log.isDebugEnabled()) { log.debug( "Non positive status code was returned from the call. Will close the span [" + this.span + "]"); } throwable = new RestClientException("Status code of the response is [" + clientResponse.statusCode().value() + "] and the reason is [" + clientResponse.statusCode().getReasonPhrase() + "]"); } handleReceive(this.span, this.ws, clientResponse, throwable); }
/** * @param status * @param translatableMessage */ public RestMessage(HttpStatus status, TranslatableMessage message) { super(); this.message = message.translate(Common.getTranslations()); if(status.is1xxInformational()||status.is2xxSuccessful()) this.level = RestMessageLevel.INFORMATION; else if(status.is3xxRedirection()) this.level = RestMessageLevel.WARNING; else if(status.is4xxClientError() || status.is5xxServerError()) this.level = RestMessageLevel.ERROR; this.status = status; }
public static Tag outcome(ClientHttpResponse response) { try { if (response != null) { HttpStatus statusCode = response.getStatusCode(); if (statusCode.is1xxInformational()) { return OUTCOME_INFORMATIONAL; } if (statusCode.is2xxSuccessful()) { return OUTCOME_SUCCESS; } if (statusCode.is3xxRedirection()) { return OUTCOME_REDIRECTION; } if (statusCode.is4xxClientError()) { return OUTCOME_CLIENT_ERROR; } if (statusCode.is5xxServerError()) { return OUTCOME_SERVER_ERROR; } } return OUTCOME_UNKNOWN; } catch (IOException | IllegalArgumentException e) { return OUTCOME_UNKNOWN; } } }