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
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! This module contains enum Error.
//! Error type represents all possible errors that can occur when dealing
//! with the generic or any dedicated-exchange API


use serde_json;
use hyper;
use data_encoding;
use exchange::Exchange;

error_chain!{
    types {
        Error, ErrorKind, ResultExt, Result;
    }

    foreign_links {
        Json(serde_json::Error);
        ParseFloat(::std::num::ParseFloatError);
        ParseString(::std::string::FromUtf8Error);
        Hyper(hyper::Error);
        DataDecoding(data_encoding::DecodeError);
        Io(::std::io::Error);
    }

    errors {
        BadParse {
            description("ParsingError")
                display("The response could not be parsed.")
        }

        ServiceUnavailable(reason: String) {
            description("ServiceUnavailable")
                display("Host could not be reached: {}.", reason)
        }

        BadCredentials {
            description("BadCredentials")
                display("The informations provided do not allow authentication.")
        }

        RateLimitExceeded {
            description("RateLimitExceeded")
                display("API call rate limit exceeded.")
        }

        PairUnsupported {
            description("PairUnsupported")
                display("This pair is not supported.")
        }

        InvalidArguments {
            description("InvalidArguments")
                display("Arguments passed do not conform to the protocol.")
        }

        ExchangeSpecificError(reason: String) {
            description("ExchangeSpecificError")
                display("Exchange error: {}", reason)
        }

        TlsError {
            description("TlsError")
                display("Fail to initialize TLS client.")
        }

        InvalidFieldFormat(field: String) {
            description("InvalidFieldFormat")
                display("Fail to parse field \"{}\".", field)
        }

        InvalidFieldValue(field: String) {
            description("InvalidFieldValue")
                display("Invalid value for field \"{}\".", field)
        }

        MissingField(field: String) {
            description("MissingFiled")
                display("Missing field \"{}\".", field)
        }

        InsufficientFunds {
            description("InsufficientFunds")
                display("You haven't enough founds.")
        }

        InsufficientOrderSize {
            description("InsufficientOrderSize")
                display("Your order is not big enough.")
        }

        MissingPrice{
            description("MissingPrice")
                display("No price specified.")
        }

        InvalidConfigType(expected: Exchange, find: Exchange){
            description("InvalidConfigType")
                display("Invalid config: \nExpected: {:?}\nFind: {:?}", expected, find)
        }

        InvalidExchange(value: String) {
            description("InvalidExchange")
                display("Invalid exchange: \"{}\"", value)
        }

        InvalidNonce {
            description("InvalidNonce")
                display("Invalid nonce")
        }

        PermissionDenied {
            description("PermissionDenied")
                display("The operation cannot be done with the provided credentials")
        }
    }
}