morpheus_network/
error.rs

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
//! Network error types

extern crate alloc;

use core::fmt;

pub type Result<T> = core::result::Result<T, NetworkError>;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NetworkError {
    ProtocolNotAvailable,
    InitializationFailed,
    DnsResolutionFailed,
    ConnectionFailed,
    NotConnected,
    Timeout,
    HttpError(u16),
    InvalidUrl,
    InvalidResponse,
    FileError,
    OutOfMemory,
    Cancelled,
    TlsError,
    /// TLS/HTTPS is not supported - use HTTP URLs
    TlsNotSupported,
    /// Device-level error with description.
    DeviceError(alloc::string::String),
    /// Buffer too small for operation.
    BufferTooSmall,
    /// Response exceeded size limit.
    ResponseTooLarge,
    /// Too many redirects.
    TooManyRedirects,
    /// Send operation failed.
    SendFailed,
    /// Receive operation failed.
    ReceiveFailed,
    /// Unexpected end of stream.
    UnexpectedEof,
    Unknown,
}

impl fmt::Display for NetworkError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::ProtocolNotAvailable => write!(f, "Network protocol not available"),
            Self::InitializationFailed => write!(f, "Network initialization failed"),
            Self::DnsResolutionFailed => write!(f, "DNS resolution failed"),
            Self::ConnectionFailed => write!(f, "Connection failed"),
            Self::NotConnected => write!(f, "Not connected"),
            Self::Timeout => write!(f, "Request timed out"),
            Self::HttpError(code) => write!(f, "HTTP error: {}", code),
            Self::InvalidUrl => write!(f, "Invalid URL"),
            Self::InvalidResponse => write!(f, "Invalid response from server"),
            Self::FileError => write!(f, "File I/O error"),
            Self::OutOfMemory => write!(f, "Out of memory"),
            Self::Cancelled => write!(f, "Operation cancelled"),
            Self::TlsError => write!(f, "TLS/HTTPS error"),
            Self::TlsNotSupported => write!(f, "HTTPS not supported - use HTTP URL"),
            Self::DeviceError(msg) => write!(f, "Device error: {}", msg),
            Self::BufferTooSmall => write!(f, "Buffer too small"),
            Self::ResponseTooLarge => write!(f, "Response too large"),
            Self::TooManyRedirects => write!(f, "Too many redirects"),
            Self::SendFailed => write!(f, "Send failed"),
            Self::ReceiveFailed => write!(f, "Receive failed"),
            Self::UnexpectedEof => write!(f, "Unexpected end of stream"),
            Self::Unknown => write!(f, "Unknown error"),
        }
    }
}