1use serde_json::error::Error as ParserError;
2use std::error::Error;
3use std::fmt::{self, Display};
4use url::ParseError;
5
6use self::EurekaClientError::*;
7
8#[derive(Debug)]
10pub enum EurekaClientError {
11 ClientError(reqwest::Error),
13 JsonError(ParserError),
15 GenericError(String),
17 InvalidUri(ParseError),
19 InternalServerError,
21 BadRequest,
23 NotFound,
25}
26
27impl Error for EurekaClientError {
28 fn source(&self) -> Option<&(dyn Error + 'static)> {
29 match *self {
30 ClientError(ref error) => Some(error),
31 JsonError(ref error) => Some(error),
32 InvalidUri(ref error) => Some(error),
33 _ => None,
34 }
35 }
36}
37
38impl From<reqwest::Error> for EurekaClientError {
39 fn from(err: reqwest::Error) -> EurekaClientError {
40 ClientError(err)
41 }
42}
43
44impl From<ParserError> for EurekaClientError {
45 fn from(err: ParserError) -> EurekaClientError {
46 JsonError(err)
47 }
48}
49
50impl From<ParseError> for EurekaClientError {
51 fn from(err: ParseError) -> EurekaClientError {
52 InvalidUri(err)
53 }
54}
55
56impl Display for EurekaClientError {
57 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58 match self {
59 ClientError(e) => write!(f, "HTTP client error: {}", e),
60 JsonError(e) => write!(f, "JSON parsing error: {}", e),
61 GenericError(s) => write!(f, "Generic error: {}", s),
62 InvalidUri(e) => write!(f, "Invalid URI: {}", e),
63 InternalServerError => write!(f, "Internal server error (500)"),
64 BadRequest => write!(f, "Bad request (400)"),
65 NotFound => write!(f, "Not found (404)"),
66 }
67 }
68}