1use std::error::Error;
2use std::fmt::Display;
3use std::fmt;
4use std::convert::From;
5use hyper::error::Error as HyperError;
6use serde_json::error::Error as ParserError;
7use hyper::error::UriError;
8
9use self::EurekaClientError::*;
10
11#[derive(Debug)]
13pub enum EurekaClientError {
14 ClientError(HyperError),
16 JsonError(ParserError),
18 GenericError(String),
20 InvalidUri(UriError),
22 InternalServerError,
24 BadRequest,
26 NotFound
28}
29
30impl Error for EurekaClientError {
31 fn description(&self) -> &str {
32 match *self {
33 ClientError(_) => "Error calling downstream client: ",
34 JsonError(_) => "A json error occurred ",
35 BadRequest => "Received a 400 (Bad Request) response",
36 _ => "Some error occurred"
37 }
38 }
39
40 fn cause(&self) -> Option<&Error> {
41 match *self {
42 ClientError(ref error) => Some(error as &Error),
43 JsonError(ref error) => Some(error as &Error),
44 _ => None
45 }
46 }
47}
48
49impl From<HyperError> for EurekaClientError {
50 fn from(err: HyperError) -> EurekaClientError {
51 ClientError(err)
52 }
53}
54
55impl From<ParserError> for EurekaClientError {
56 fn from(err: ParserError) -> EurekaClientError {
57 JsonError(err)
58 }
59}
60
61impl From<UriError> for EurekaClientError {
62 fn from(err: UriError) -> EurekaClientError {
63 InvalidUri(err)
64 }
65}
66
67impl Display for EurekaClientError {
68 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69 write!(f, "{}", self.description())
70 }
71}