本文整理了Java中org.springframework.web.reactive.function.client.WebClientResponseException.getStatusCode()
方法的一些代码示例,展示了WebClientResponseException.getStatusCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClientResponseException.getStatusCode()
方法的具体详情如下:
包路径:org.springframework.web.reactive.function.client.WebClientResponseException
类名称:WebClientResponseException
方法名:getStatusCode
[英]Return the HTTP status code value.
[中]返回HTTP状态代码值。
代码示例来源:origin: spring-projects/spring-framework
assertTrue(throwable instanceof WebClientResponseException);
WebClientResponseException ex = (WebClientResponseException) throwable;
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, ex.getStatusCode());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getRawStatusCode());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),
代码示例来源:origin: com.vmware.card-connectors/core
public static <R> Mono<R> skipOnStatus(Throwable throwable, Predicate<HttpStatus> statusPredicate) {
if (throwable instanceof WebClientResponseException
&& statusPredicate.test(WebClientResponseException.class.cast(throwable).getStatusCode())) {
return Mono.empty();
} else {
return Mono.error(throwable);
}
}
代码示例来源:origin: com.vmware.card-connectors/connectors-config
@ExceptionHandler
@ResponseBody
public ResponseEntity<Object> handleStatusCodeException(WebClientResponseException e) {
// Map the status to a 500 unlesss it's a 401. If that's the case
// then we know the client has passed in an invalid X-xxx-Authorization header and it's a 400.
logger.error("Backend returned {} {} \n {}", e.getStatusCode(), e.getStatusCode().getReasonPhrase(), e.getResponseBodyAsString());
String backendStatus = Integer.toString(e.getRawStatusCode());
if (e.getStatusCode() == UNAUTHORIZED) {
Map<String, String> body = Collections.singletonMap("error", "invalid_connector_token");
return ResponseEntity.status(BAD_REQUEST)
.header(BACKEND_STATUS, backendStatus)
.contentType(APPLICATION_JSON)
.body(body);
} else {
BodyBuilder builder = ResponseEntity.status(INTERNAL_SERVER_ERROR)
.header(BACKEND_STATUS, backendStatus);
if (e.getHeaders().getContentType() != null) {
builder.contentType(e.getHeaders().getContentType());
}
return builder.body(e.getResponseBodyAsString());
}
}
}
代码示例来源:origin: org.springframework.vault/spring-vault-core
if (e.getStatusCode().is4xxClientError()) {
代码示例来源:origin: org.springframework.boot/spring-boot-actuator-autoconfigure
private Throwable mapError(Throwable throwable) {
if (throwable instanceof WebClientResponseException) {
HttpStatus statusCode = ((WebClientResponseException) throwable)
.getStatusCode();
if (statusCode.equals(HttpStatus.FORBIDDEN)) {
return new CloudFoundryAuthorizationException(Reason.ACCESS_DENIED,
"Access denied");
}
if (statusCode.is4xxClientError()) {
return new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN,
"Invalid token", throwable);
}
}
return new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE,
"Cloud controller not reachable");
}
内容来源于网络,如有侵权,请联系作者删除!