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    ResponseTooLarge,
24
25    // Infrastructure
26    InvalidIpcStatusCode,
27    Disconnected,
28}
29
30impl std::fmt::Display for NetworkError {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        use NetworkError::*;
33        let msg = match self {
34            InvalidUri => "invalid URI",
35            MissingHost => "URI has no host",
36            InvalidDnsName => "invalid DNS name",
37
38            ConnectionFailed => "connection failed",
39            TlsFailed => "TLS handshake failed",
40            Timeout => "network timeout",
41
42            HttpHandshakeFailed => "HTTP handshake failed",
43            HttpRequestFailed => "HTTP request failed",
44            HttpResponseFailed => "HTTP response failed",
45            TooManyRedirects => "too many redirects",
46            UnsupportedHttpVersion => "unsupported HTTP version",
47            ResponseTooLarge => "response body exceeded the allowed size",
48
49            InvalidIpcStatusCode => "invalid HTTP status received via IPC",
50            Disconnected => "network subsystem disconnected",
51        };
52        write!(f, "{msg}")
53    }
54}
55
56impl std::error::Error for NetworkError {}