1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::error::{Error, ErrorKind, ErrorResponse};
pub use sync15_traits::telemetry::*;
impl<'a> From<&'a Error> for SyncFailure {
fn from(e: &Error) -> SyncFailure {
match e.kind() {
ErrorKind::TokenserverHttpError(status) => {
if *status == 401 {
SyncFailure::Auth {
from: "tokenserver",
}
} else {
SyncFailure::Http { code: *status }
}
}
ErrorKind::BackoffError(_) => SyncFailure::Http { code: 503 },
ErrorKind::StorageHttpError(ref e) => match e {
ErrorResponse::NotFound { .. } => SyncFailure::Http { code: 404 },
ErrorResponse::Unauthorized { .. } => SyncFailure::Auth { from: "storage" },
ErrorResponse::PreconditionFailed { .. } => SyncFailure::Http { code: 412 },
ErrorResponse::ServerError { status, .. } => SyncFailure::Http { code: *status },
ErrorResponse::RequestFailed { status, .. } => SyncFailure::Http { code: *status },
},
ErrorKind::CryptoError(ref e) => SyncFailure::Unexpected {
error: e.to_string(),
},
ErrorKind::RequestError(ref e) => SyncFailure::Unexpected {
error: e.to_string(),
},
ErrorKind::UnexpectedStatus(ref e) => SyncFailure::Http { code: e.status },
ErrorKind::Interrupted(ref e) => SyncFailure::Unexpected {
error: e.to_string(),
},
e => SyncFailure::Other {
error: e.to_string(),
},
}
}
}