civo_rs/
errors.rs

1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug)]
5pub struct HTTPError {
6    pub code: u16,
7    pub message: String,
8}
9
10#[derive(Debug)]
11pub struct GenericError {
12   pub  message: String
13}
14
15impl fmt::Display for GenericError {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        write!(f, "error {}", self.message)
18    }
19}
20
21
22impl GenericError {
23    pub fn new(message: &str) -> GenericError {
24        GenericError {
25            message: message.to_string()
26        }
27    }
28}
29
30
31impl Error for GenericError{}
32
33
34impl HTTPError {
35    pub fn new(code: u16, message: &str) -> HTTPError {
36        HTTPError {
37            code,
38            message: message.to_string(),
39        }
40    }
41}
42
43impl fmt::Display for HTTPError {
44    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45        write!(f, "HTTP error {} : {}", self.code, self.message)
46    }
47}
48
49impl Error for HTTPError {}