org.springframework.web.reactive.function.client.WebClientResponseException.getRawStatusCode()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(174)

本文整理了Java中org.springframework.web.reactive.function.client.WebClientResponseException.getRawStatusCode()方法的一些代码示例,展示了WebClientResponseException.getRawStatusCode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClientResponseException.getRawStatusCode()方法的具体详情如下:
包路径:org.springframework.web.reactive.function.client.WebClientResponseException
类名称:WebClientResponseException
方法名:getRawStatusCode

WebClientResponseException.getRawStatusCode介绍

[英]Return the raw HTTP status code value.
[中]返回原始HTTP状态代码值。

代码示例

代码示例来源:origin: spring-projects/spring-framework

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(),
    ex.getStatusText());

代码示例来源:origin: org.springframework.vault/spring-vault-core

private static String format(String message, WebClientResponseException e) {
  return String.format("%s: Status %s %s %s", message, e.getRawStatusCode(),
      e.getStatusText(), VaultResponses.getError(e.getResponseBodyAsString()));
}

代码示例来源: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());
    }
  }
}

相关文章