Skip to main content

orinium_browser/platform/network/
error.rs

1//! Network error types.
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Deserialize, Serialize)]
6pub enum NetworkError {
7    // Request / protocol
8    InvalidUri,
9    MissingHost,
10    InvalidDnsName,
11
12    // Transport
13    ConnectionFailed,
14    TlsFailed,
15    Timeout,
16
17    // HTTP
18    HttpHandshakeFailed,
19    HttpRequestFailed,
20    HttpResponseFailed,
21    TooManyRedirects,
22    UnsupportedHttpVersion,
23
24    // Infrastructure
25    InvalidIpcStatusCode,
26    Disconnected,
27}
28
29impl std::fmt::Display for NetworkError {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        use NetworkError::*;
32        let msg = match self {
33            InvalidUri => "invalid URI",
34            MissingHost => "URI has no host",
35            InvalidDnsName => "invalid DNS name",
36
37            ConnectionFailed => "connection failed",
38            TlsFailed => "TLS handshake failed",
39            Timeout => "network timeout",
40
41            HttpHandshakeFailed => "HTTP handshake failed",
42            HttpRequestFailed => "HTTP request failed",
43            HttpResponseFailed => "HTTP response failed",
44            TooManyRedirects => "too many redirects",
45            UnsupportedHttpVersion => "unsupported HTTP version",
46
47            InvalidIpcStatusCode => "invalid HTTP status received via IPC",
48            Disconnected => "network subsystem disconnected",
49        };
50        write!(f, "{msg}")
51    }
52}
53
54impl std::error::Error for NetworkError {}