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 47 48 49 50 51 52 53 54 55 56 57 58 59
use super::serialization::{DecodeError, EncodeError}; use actix::MailboxError; use std::io; #[derive(Clone, Debug, thiserror::Error)] #[error("Timeout connecting GSB at `{0}`")] pub struct ConnectionTimeout(pub ya_sb_proto::GsbAddr); #[derive(Debug, thiserror::Error)] pub enum Error { #[error("Connecting GSB at `{0}` failure: {1}")] ConnectionFail(ya_sb_proto::GsbAddr, io::Error), #[error(transparent)] ConnectionTimeout(#[from] ConnectionTimeout), #[error("Called service `{0}` is unavailable")] Closed(String), #[error("Service receiver was cancelled")] Cancelled, #[error("No such endpoint `{0}`")] NoEndpoint(String), #[error("Bad content: {0}")] BadContent(#[from] DecodeError), #[error("Encoding problem: {0}")] EncodingProblem(String), #[error("Timeout calling `{0}` service")] Timeout(String), #[error("Bad request: {0}")] GsbBadRequest(String), #[error("Already registered: `{0}`")] GsbAlreadyRegistered(String), #[error("GSB failure: {0}")] GsbFailure(String), #[error("Remote service at `{0}` error: {1}")] RemoteError(String, String), } impl From<MailboxError> for Error { fn from(e: MailboxError) -> Self { match e { MailboxError::Closed => Error::Closed("unknown".into()), MailboxError::Timeout => Error::Timeout("unknown".into()), } } } impl Error { pub(crate) fn from_addr(addr: String, e: MailboxError) -> Self { match e { MailboxError::Closed => Error::Closed(addr), MailboxError::Timeout => Error::Timeout(addr), } } } impl From<EncodeError> for Error { fn from(e: EncodeError) -> Self { Error::EncodingProblem(format!("{}", e)) } }