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
use serde::{Deserialize, Serialize};

pub type VndbResult<T> = Result<T, VndbError>;

#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(tag = "id", rename_all = "lowercase")]
pub enum VndbError {
    Parse {
        msg: String,
    },
    Missing {
        msg: String,
        field: String,
    },
    BadArg {
        msg: String,
        field: String,
    },
    NeedLogin {
        msg: String,
    },
    Throttled {
        msg: String,
        typ: String,
        minwait: f64,
        fullwait: f64,
    },
    Auth {
        msg: String,
    },
    LoggedIn {
        msg: String,
    },
    GetType {
        msg: String,
    },
    GetInfo {
        msg: String,
        flag: String,
    },
    Filter {
        msg: String,
        field: String,
        op: String,
        value: String,
    },
    SetType {
        msg: String,
    },
    IO {
        msg: String,
    },
    Other {
        msg: String,
    },
}

impl VndbError {
    pub(crate) fn parse_error(buf: &[u8]) -> Result<Self, serde_json::Error> {
        let error: VndbError = serde_json::from_slice(&buf)?;
        println!("{:#?}", error);
        Ok(error)
    }
}