Skip to main content

core_invoice/
error.rs

1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum AmountError {
5    TooManyDecimals,
6    Overflow,
7}
8
9impl fmt::Display for AmountError {
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11        match self {
12            Self::TooManyDecimals => write!(f, "amount has more than two fraction digits"),
13            Self::Overflow => write!(f, "amount overflow"),
14        }
15    }
16}
17
18impl std::error::Error for AmountError {}
19
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub enum DateError {
22    Invalid,
23}
24
25impl fmt::Display for DateError {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        write!(f, "not an EN 16931 calendar date (YYYY-MM-DD, no time)")
28    }
29}
30
31impl std::error::Error for DateError {}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub enum AttachmentError {
35    EmptyMime,
36    EmptyFilename,
37}
38
39impl fmt::Display for AttachmentError {
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            Self::EmptyMime => write!(f, "attachment mime code shall be present"),
43            Self::EmptyFilename => write!(f, "attachment filename shall be present"),
44        }
45    }
46}
47
48impl std::error::Error for AttachmentError {}