Skip to content

Commit ed6692b

Browse files
committed
refactor(crates-io): rename ResponseError to Error
1 parent 00a8727 commit ed6692b

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

crates/crates-io/lib.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct Crates {
126126
}
127127

128128
#[derive(Debug)]
129-
pub enum ResponseError {
129+
pub enum Error {
130130
Curl(curl::Error),
131131
Api {
132132
code: u32,
@@ -141,29 +141,29 @@ pub enum ResponseError {
141141
Other(anyhow::Error),
142142
}
143143

144-
impl std::error::Error for ResponseError {
144+
impl std::error::Error for Error {
145145
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
146146
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()),
151151
}
152152
}
153153
}
154154

155-
impl fmt::Display for ResponseError {
155+
impl fmt::Display for Error {
156156
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
157157
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, .. } => {
160160
f.write_str("the remote server responded with an error")?;
161161
if *code != 200 {
162162
write!(f, " (status {} {})", code, reason(*code))?;
163163
};
164164
write!(f, ": {}", errors.join(", "))
165165
}
166-
ResponseError::Code {
166+
Self::Code {
167167
code,
168168
headers,
169169
body,
@@ -178,14 +178,14 @@ impl fmt::Display for ResponseError {
178178
headers.join("\n\t"),
179179
body
180180
),
181-
ResponseError::Other(..) => write!(f, "invalid response from server"),
181+
Self::Other(..) => write!(f, "invalid response from server"),
182182
}
183183
}
184184
}
185185

186-
impl From<curl::Error> for ResponseError {
186+
impl From<curl::Error> for Error {
187187
fn from(error: curl::Error) -> Self {
188-
ResponseError::Curl(error)
188+
Self::Curl(error)
189189
}
190190
}
191191

@@ -301,7 +301,7 @@ impl Registry {
301301
let body = self
302302
.handle(&mut |buf| body.read(buf).unwrap_or(0))
303303
.map_err(|e| match e {
304-
ResponseError::Code { code, .. }
304+
Error::Code { code, .. }
305305
if code == 503
306306
&& started.elapsed().as_secs() >= 29
307307
&& self.host_is_crates_io() =>
@@ -414,7 +414,7 @@ impl Registry {
414414
fn handle(
415415
&mut self,
416416
read: &mut dyn FnMut(&mut [u8]) -> usize,
417-
) -> std::result::Result<String, ResponseError> {
417+
) -> std::result::Result<String, Error> {
418418
let mut headers = Vec::new();
419419
let mut body = Vec::new();
420420
{
@@ -441,7 +441,7 @@ impl Registry {
441441
let body = match String::from_utf8(body) {
442442
Ok(body) => body,
443443
Err(..) => {
444-
return Err(ResponseError::Other(format_err!(
444+
return Err(Error::Other(format_err!(
445445
"response body was not valid utf-8"
446446
)))
447447
}
@@ -452,12 +452,12 @@ impl Registry {
452452

453453
match (self.handle.response_code()?, errors) {
454454
(0, None) | (200, None) => Ok(body),
455-
(code, Some(errors)) => Err(ResponseError::Api {
455+
(code, Some(errors)) => Err(Error::Api {
456456
code,
457457
headers,
458458
errors,
459459
}),
460-
(code, None) => Err(ResponseError::Code {
460+
(code, None) => Err(Error::Code {
461461
code,
462462
headers,
463463
body,

0 commit comments

Comments
 (0)