@@ -11,8 +11,7 @@ use bytes::Bytes;
11
11
use futures_core:: Stream ;
12
12
use serde:: de:: DeserializeOwned ;
13
13
14
- /// Represents a streaming, untyped byte stream for both success and error
15
- /// responses.
14
+ /// Represents an untyped byte stream for both success and error responses.
16
15
pub type ByteStream =
17
16
Pin < Box < dyn Stream < Item = reqwest:: Result < Bytes > > + Send > > ;
18
17
@@ -136,6 +135,9 @@ impl<T: std::fmt::Debug> std::fmt::Debug for ResponseValue<T> {
136
135
/// or an enum if there are multiple valid error types. It can be the unit type
137
136
/// if there are no structured returns expected.
138
137
pub enum Error < E = ( ) > {
138
+ /// The request did not conform to API requirements.
139
+ InvalidRequest ( String ) ,
140
+
139
141
/// A server error either with the data, or with the connection.
140
142
CommunicationError ( reqwest:: Error ) ,
141
143
@@ -155,6 +157,7 @@ impl<E> Error<E> {
155
157
/// Returns the status code, if the error was generated from a response.
156
158
pub fn status ( & self ) -> Option < reqwest:: StatusCode > {
157
159
match self {
160
+ Error :: InvalidRequest ( _) => None ,
158
161
Error :: CommunicationError ( e) => e. status ( ) ,
159
162
Error :: ErrorResponse ( rv) => Some ( rv. status ( ) ) ,
160
163
Error :: InvalidResponsePayload ( e) => e. status ( ) ,
@@ -166,6 +169,7 @@ impl<E> Error<E> {
166
169
/// handling with APIs that distinguish various error response bodies.
167
170
pub fn into_untyped ( self ) -> Error {
168
171
match self {
172
+ Error :: InvalidRequest ( s) => Error :: InvalidRequest ( s) ,
169
173
Error :: CommunicationError ( e) => Error :: CommunicationError ( e) ,
170
174
Error :: ErrorResponse ( ResponseValue {
171
175
inner : _,
@@ -193,17 +197,20 @@ impl<E> From<reqwest::Error> for Error<E> {
193
197
impl < E > std:: fmt:: Display for Error < E > {
194
198
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
195
199
match self {
200
+ Error :: InvalidRequest ( s) => {
201
+ write ! ( f, "Invalid Request: {}" , s)
202
+ }
196
203
Error :: CommunicationError ( e) => {
197
- write ! ( f, "Communication Error {}" , e)
204
+ write ! ( f, "Communication Error: {}" , e)
198
205
}
199
206
Error :: ErrorResponse ( _) => {
200
207
write ! ( f, "Error Response" )
201
208
}
202
209
Error :: InvalidResponsePayload ( e) => {
203
- write ! ( f, "Invalid Response Payload {}" , e)
210
+ write ! ( f, "Invalid Response Payload: {}" , e)
204
211
}
205
212
Error :: UnexpectedResponse ( r) => {
206
- write ! ( f, "Unexpected Response {:?}" , r)
213
+ write ! ( f, "Unexpected Response: {:?}" , r)
207
214
}
208
215
}
209
216
}
0 commit comments