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
use blaze_pk::error::DecodeError;
use database::DbErr;
use std::{fmt::Display, io};

pub type BlazeResult<T> = Result<T, BlazeError>;
pub type ServerResult<T> = Result<T, ServerError>;

#[derive(Debug)]
pub enum BlazeError {
    Decode(DecodeError),
    IO(io::Error),
    Other(&'static str),
    Database(DbErr),
    Server(ServerError),
}

impl Display for BlazeError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Decode(value) => write!(f, "Decode error occurred: {value:?}"),
            Self::IO(value) => write!(f, "IO error: {value:?}"),
            Self::Other(value) => write!(f, "Other: {value}"),
            Self::Database(value) => write!(f, "Database error: {value}"),
            Self::Server(value) => write!(f, "Server error: {value:?}"),
        }
    }
}

impl From<DecodeError> for BlazeError {
    fn from(err: DecodeError) -> Self {
        BlazeError::Decode(err)
    }
}

impl From<io::Error> for BlazeError {
    fn from(err: io::Error) -> Self {
        BlazeError::IO(err)
    }
}

impl From<DbErr> for BlazeError {
    fn from(err: DbErr) -> Self {
        BlazeError::Database(err)
    }
}

impl From<ServerError> for BlazeError {
    fn from(err: ServerError) -> Self {
        BlazeError::Server(err)
    }
}

///  Enum for server error values
#[derive(Debug, Clone)]
#[repr(u16)]
#[allow(unused)]
pub enum ServerError {
    ServerUnavailable = 0x0,
    EmailNotFound = 0xB,
    WrongPassword = 0xC,
    InvalidSession = 0xD,
    EmailAlreadyInUse = 0x0F,
    AgeRestriction = 0x10,
    InvalidAccount = 0x11,
    BannedAccount = 0x13,
    InvalidInformation = 0x15,
    InvalidEmail = 0x16,
    LegalGuardianRequired = 0x2A,
    CodeRequired = 0x32,
    KeyCodeAlreadyInUse = 0x33,
    InvalidCerberusKey = 0x34,
    ServerUnavailableFinal = 0x4001,
    FailedNoLoginAction = 0x4004,
    ServerUnavailableNothing = 0x4005,
    ConnectionLost = 0x4007,
    // Errors from suspend
    Suspend12D = 0x12D,
    Suspend12E = 0x12E,
}