@@ -11,8 +11,7 @@ use bytes::Bytes;
1111use futures_core:: Stream ;
1212use serde:: de:: DeserializeOwned ;
1313
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.
1615pub type ByteStream =
1716 Pin < Box < dyn Stream < Item = reqwest:: Result < Bytes > > + Send > > ;
1817
@@ -136,6 +135,9 @@ impl<T: std::fmt::Debug> std::fmt::Debug for ResponseValue<T> {
136135/// or an enum if there are multiple valid error types. It can be the unit type
137136/// if there are no structured returns expected.
138137pub enum Error < E = ( ) > {
138+ /// The request did not conform to API requirements.
139+ InvalidRequest ( String ) ,
140+
139141 /// A server error either with the data, or with the connection.
140142 CommunicationError ( reqwest:: Error ) ,
141143
@@ -155,6 +157,7 @@ impl<E> Error<E> {
155157 /// Returns the status code, if the error was generated from a response.
156158 pub fn status ( & self ) -> Option < reqwest:: StatusCode > {
157159 match self {
160+ Error :: InvalidRequest ( _) => None ,
158161 Error :: CommunicationError ( e) => e. status ( ) ,
159162 Error :: ErrorResponse ( rv) => Some ( rv. status ( ) ) ,
160163 Error :: InvalidResponsePayload ( e) => e. status ( ) ,
@@ -166,6 +169,7 @@ impl<E> Error<E> {
166169 /// handling with APIs that distinguish various error response bodies.
167170 pub fn into_untyped ( self ) -> Error {
168171 match self {
172+ Error :: InvalidRequest ( s) => Error :: InvalidRequest ( s) ,
169173 Error :: CommunicationError ( e) => Error :: CommunicationError ( e) ,
170174 Error :: ErrorResponse ( ResponseValue {
171175 inner : _,
@@ -193,17 +197,20 @@ impl<E> From<reqwest::Error> for Error<E> {
193197impl < E > std:: fmt:: Display for Error < E > {
194198 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
195199 match self {
200+ Error :: InvalidRequest ( s) => {
201+ write ! ( f, "Invalid Request: {}" , s)
202+ }
196203 Error :: CommunicationError ( e) => {
197- write ! ( f, "Communication Error {}" , e)
204+ write ! ( f, "Communication Error: {}" , e)
198205 }
199206 Error :: ErrorResponse ( _) => {
200207 write ! ( f, "Error Response" )
201208 }
202209 Error :: InvalidResponsePayload ( e) => {
203- write ! ( f, "Invalid Response Payload {}" , e)
210+ write ! ( f, "Invalid Response Payload: {}" , e)
204211 }
205212 Error :: UnexpectedResponse ( r) => {
206- write ! ( f, "Unexpected Response {:?}" , r)
213+ write ! ( f, "Unexpected Response: {:?}" , r)
207214 }
208215 }
209216 }
0 commit comments