|
3 | 3 |
|
4 | 4 | //! HTTP responses. |
5 | 5 |
|
6 | | -use crate::{ |
7 | | - error::HttpError, |
8 | | - http::{headers::Headers, DeserializeWith, Format, JsonFormat, StatusCode}, |
9 | | -}; |
| 6 | +use crate::http::{headers::Headers, DeserializeWith, Format, JsonFormat, StatusCode}; |
10 | 7 | use bytes::Bytes; |
11 | 8 | use futures::{Stream, StreamExt}; |
12 | 9 | use serde::de::DeserializeOwned; |
13 | 10 | use std::{fmt, marker::PhantomData, pin::Pin}; |
14 | | -use typespec::{ |
15 | | - error::{ErrorKind, ResultExt}, |
16 | | - Error, |
17 | | -}; |
| 11 | +use typespec::error::{ErrorKind, ResultExt}; |
18 | 12 |
|
19 | 13 | #[cfg(not(target_arch = "wasm32"))] |
20 | 14 | pub type PinnedStream = Pin<Box<dyn Stream<Item = crate::Result<Bytes>> + Send>>; |
@@ -83,24 +77,6 @@ pub struct Response<T, F = JsonFormat> { |
83 | 77 | } |
84 | 78 |
|
85 | 79 | impl<T, F> Response<T, F> { |
86 | | - pub async fn success(self) -> crate::Result<Self> { |
87 | | - let status = self.status(); |
88 | | - if status.is_success() { |
89 | | - Ok(self) |
90 | | - } else { |
91 | | - let http_error = HttpError::new(self.raw).await; |
92 | | - let error_kind = ErrorKind::http_response( |
93 | | - status, |
94 | | - http_error.error_code().map(std::borrow::ToOwned::to_owned), |
95 | | - ); |
96 | | - Err(Error::full( |
97 | | - error_kind, |
98 | | - http_error, |
99 | | - format!("server returned an error response: {status}"), |
100 | | - )) |
101 | | - } |
102 | | - } |
103 | | - |
104 | 80 | /// Get the status code from the response. |
105 | 81 | pub fn status(&self) -> StatusCode { |
106 | 82 | self.raw.status() |
|
0 commit comments