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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! Note: this mostly just reexports the things from sync15_traits::telemetry.

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(),
            },
        }
    }
}