use of cn.taketoday.http.HttpStatus in project today-infrastructure by TAKETODAY.
the class DefaultClientResponse method createException.
@Override
public Mono<WebClientResponseException> createException() {
return bodyToMono(byte[].class).defaultIfEmpty(EMPTY).onErrorReturn(ex -> !(ex instanceof Error), EMPTY).map(bodyBytes -> {
HttpRequest request = this.requestSupplier.get();
Charset charset = headers().contentType().map(MimeType::getCharset).orElse(null);
int statusCode = rawStatusCode();
HttpStatus httpStatus = HttpStatus.resolve(statusCode);
if (httpStatus != null) {
return WebClientResponseException.create(statusCode, httpStatus.getReasonPhrase(), headers().asHttpHeaders(), bodyBytes, charset, request);
} else {
return new UnknownHttpStatusCodeException(statusCode, headers().asHttpHeaders(), bodyBytes, charset, request);
}
});
}
use of cn.taketoday.http.HttpStatus in project today-infrastructure by TAKETODAY.
the class DefaultClientResponseTests method statusCode.
@Test
public void statusCode() {
HttpStatus status = HttpStatus.CONTINUE;
given(mockResponse.getStatusCode()).willReturn(status);
assertThat(defaultClientResponse.statusCode()).isEqualTo(status);
}
use of cn.taketoday.http.HttpStatus in project today-infrastructure by TAKETODAY.
the class ExchangeFilterFunctionsTests method statusHandlerNoMatch.
@Test
public void statusHandlerNoMatch() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
ClientResponse response = mock(ClientResponse.class);
given(response.statusCode()).willReturn(HttpStatus.NOT_FOUND);
Mono<ClientResponse> result = ExchangeFilterFunctions.statusError(HttpStatus::is5xxServerError, req -> new MyException()).filter(request, req -> Mono.just(response));
StepVerifier.create(result).expectNext(response).expectComplete().verify();
}
use of cn.taketoday.http.HttpStatus in project today-infrastructure by TAKETODAY.
the class ClientResponseWrapperTests method statusCode.
@Test
public void statusCode() {
HttpStatus status = HttpStatus.BAD_REQUEST;
given(mockResponse.statusCode()).willReturn(status);
assertThat(wrapper.statusCode()).isSameAs(status);
}
use of cn.taketoday.http.HttpStatus in project today-infrastructure by TAKETODAY.
the class ErrorResponseException method getMessage.
@Override
public String getMessage() {
HttpStatus httpStatus = HttpStatus.resolve(this.status);
String message = (httpStatus != null ? httpStatus : String.valueOf(this.status)) + (!this.headers.isEmpty() ? ", headers=" + this.headers : "") + ", " + this.body;
return ExceptionUtils.buildMessage(message, getCause());
}
Aggregations