iota_ledger_nano/api/
errors.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum APIError {
5 #[error("No error")]
6 Ok,
7
8 #[error("Incorrect length")]
9 IncorrectLength,
10
11 #[error("Invalid data")]
12 CommandInvalidData,
13
14 #[error("Incorrect P1 or P2 parameter")]
15 IncorrectP1P2,
16
17 #[error("Incorrect length P3")]
18 IncorrectLengthP3,
19
20 #[error("Instruction not supported")]
21 InstructionNotSupported,
22
23 #[error("Class not supported")]
24 ClassNotSupported,
25
26 #[error("Command not allowed")]
27 CommandNotAllowed,
28
29 #[error("Security status not satisfied")]
30 SecurityStatusNotSatisfied, #[error("Conditions of use not satisfied")]
33 ConditionsOfUseNotSatisfied, #[error("Command timeout")]
36 CommandTimeout,
37
38 #[error("Transport error")]
39 TransportError,
40
41 #[error("Essence too large")]
42 EssenceTooLarge,
43
44 #[error("App version too old")]
45 AppTooOld,
46
47 #[error("Timeout")]
48 Timeout,
49
50 #[error("unknown")]
51 Unknown,
52}
53
54impl APIError {
55 pub fn get_error(rc: u16) -> APIError {
56 match rc {
57 0x9000 => APIError::Ok,
58 0x6700 => APIError::IncorrectLength,
59 0x6a80 => APIError::CommandInvalidData,
60 0x6b00 => APIError::IncorrectP1P2,
61 0x6c00 => APIError::IncorrectLengthP3,
62 0x6d00 => APIError::InstructionNotSupported,
63 0x6e00 => APIError::ClassNotSupported,
64 0x6900 => APIError::CommandNotAllowed,
65 0x6982 => APIError::SecurityStatusNotSatisfied,
66 0x6985 => APIError::ConditionsOfUseNotSatisfied,
67 0x6401 => APIError::CommandTimeout,
68 _ => APIError::Unknown,
69 }
70 }
71}