@@ -126,7 +126,7 @@ struct Crates {
126
126
}
127
127
128
128
#[ derive( Debug ) ]
129
- pub enum ResponseError {
129
+ pub enum Error {
130
130
Curl ( curl:: Error ) ,
131
131
Api {
132
132
code : u32 ,
@@ -141,29 +141,29 @@ pub enum ResponseError {
141
141
Other ( anyhow:: Error ) ,
142
142
}
143
143
144
- impl std:: error:: Error for ResponseError {
144
+ impl std:: error:: Error for Error {
145
145
fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
146
146
match self {
147
- ResponseError :: Curl ( ..) => None ,
148
- ResponseError :: Api { .. } => None ,
149
- ResponseError :: Code { .. } => None ,
150
- ResponseError :: Other ( e) => Some ( e. as_ref ( ) ) ,
147
+ Self :: Curl ( ..) => None ,
148
+ Self :: Api { .. } => None ,
149
+ Self :: Code { .. } => None ,
150
+ Self :: Other ( e) => Some ( e. as_ref ( ) ) ,
151
151
}
152
152
}
153
153
}
154
154
155
- impl fmt:: Display for ResponseError {
155
+ impl fmt:: Display for Error {
156
156
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
157
157
match self {
158
- ResponseError :: Curl ( e) => write ! ( f, "{}" , e) ,
159
- ResponseError :: Api { code, errors, .. } => {
158
+ Self :: Curl ( e) => write ! ( f, "{}" , e) ,
159
+ Self :: Api { code, errors, .. } => {
160
160
f. write_str ( "the remote server responded with an error" ) ?;
161
161
if * code != 200 {
162
162
write ! ( f, " (status {} {})" , code, reason( * code) ) ?;
163
163
} ;
164
164
write ! ( f, ": {}" , errors. join( ", " ) )
165
165
}
166
- ResponseError :: Code {
166
+ Self :: Code {
167
167
code,
168
168
headers,
169
169
body,
@@ -178,14 +178,14 @@ impl fmt::Display for ResponseError {
178
178
headers. join( "\n \t " ) ,
179
179
body
180
180
) ,
181
- ResponseError :: Other ( ..) => write ! ( f, "invalid response from server" ) ,
181
+ Self :: Other ( ..) => write ! ( f, "invalid response from server" ) ,
182
182
}
183
183
}
184
184
}
185
185
186
- impl From < curl:: Error > for ResponseError {
186
+ impl From < curl:: Error > for Error {
187
187
fn from ( error : curl:: Error ) -> Self {
188
- ResponseError :: Curl ( error)
188
+ Self :: Curl ( error)
189
189
}
190
190
}
191
191
@@ -301,7 +301,7 @@ impl Registry {
301
301
let body = self
302
302
. handle ( & mut |buf| body. read ( buf) . unwrap_or ( 0 ) )
303
303
. map_err ( |e| match e {
304
- ResponseError :: Code { code, .. }
304
+ Error :: Code { code, .. }
305
305
if code == 503
306
306
&& started. elapsed ( ) . as_secs ( ) >= 29
307
307
&& self . host_is_crates_io ( ) =>
@@ -414,7 +414,7 @@ impl Registry {
414
414
fn handle (
415
415
& mut self ,
416
416
read : & mut dyn FnMut ( & mut [ u8 ] ) -> usize ,
417
- ) -> std:: result:: Result < String , ResponseError > {
417
+ ) -> std:: result:: Result < String , Error > {
418
418
let mut headers = Vec :: new ( ) ;
419
419
let mut body = Vec :: new ( ) ;
420
420
{
@@ -441,7 +441,7 @@ impl Registry {
441
441
let body = match String :: from_utf8 ( body) {
442
442
Ok ( body) => body,
443
443
Err ( ..) => {
444
- return Err ( ResponseError :: Other ( format_err ! (
444
+ return Err ( Error :: Other ( format_err ! (
445
445
"response body was not valid utf-8"
446
446
) ) )
447
447
}
@@ -452,12 +452,12 @@ impl Registry {
452
452
453
453
match ( self . handle . response_code ( ) ?, errors) {
454
454
( 0 , None ) | ( 200 , None ) => Ok ( body) ,
455
- ( code, Some ( errors) ) => Err ( ResponseError :: Api {
455
+ ( code, Some ( errors) ) => Err ( Error :: Api {
456
456
code,
457
457
headers,
458
458
errors,
459
459
} ) ,
460
- ( code, None ) => Err ( ResponseError :: Code {
460
+ ( code, None ) => Err ( Error :: Code {
461
461
code,
462
462
headers,
463
463
body,
0 commit comments