1use super::ErrorKind;
4use http::StatusCode;
5
6impl ErrorKind {
7 pub fn http_status_code(self) -> StatusCode {
19 use ErrorKind as EK;
20 use http::StatusCode as SC;
21 match self {
22 EK::ArtiShuttingDown
23 | EK::BadApiUsage
24 | EK::BootstrapRequired
25 | EK::CacheAccessFailed
26 | EK::CacheCorrupted
27 | EK::ClockSkew
28 | EK::DirectoryExpired
29 | EK::ExternalToolFailed
30 | EK::FsPermissions
31 | EK::Internal
32 | EK::InvalidConfig
33 | EK::InvalidConfigTransition
34 | EK::KeystoreAccessFailed
35 | EK::KeystoreCorrupted
36 | EK::NoHomeDirectory
37 | EK::Other
38 | EK::PersistentStateAccessFailed
39 | EK::PersistentStateCorrupted
40 | EK::SoftwareDeprecated
41 | EK::TorDirectoryUnusable
42 | EK::TransientFailure
43 | EK::ReactorShuttingDown
44 | EK::RelayIdMismatch
45 | EK::RelayTooBusy
46 | EK::TorAccessFailed
47 | EK::TorDirectoryError => SC::INTERNAL_SERVER_ERROR,
48
49 EK::FeatureDisabled | EK::NotImplemented => SC::NOT_IMPLEMENTED,
50
51 EK::CircuitCollapse
52 | EK::CircuitRefused
53 | EK::ExitPolicyRejected
54 | EK::LocalNetworkError
55 | EK::LocalProtocolViolation
56 | EK::LocalResourceAlreadyInUse
57 | EK::LocalResourceExhausted
58 | EK::NoExit
59 | EK::NoPath => SC::SERVICE_UNAVAILABLE,
60
61 EK::TorProtocolViolation | EK::RemoteProtocolViolation | EK::RemoteNetworkFailed => {
62 SC::BAD_GATEWAY
63 }
64
65 EK::ExitTimeout | EK::TorNetworkTimeout | EK::RemoteNetworkTimeout => {
66 SC::GATEWAY_TIMEOUT
67 }
68
69 EK::ForbiddenStreamTarget => SC::FORBIDDEN,
70
71 EK::OnionServiceAddressInvalid | EK::InvalidStreamTarget => SC::BAD_REQUEST,
72 EK::OnionServiceWrongClientAuth => SC::FORBIDDEN,
73 EK::OnionServiceConnectionFailed
74 | EK::OnionServiceMissingClientAuth
75 | EK::OnionServiceNotFound
76 | EK::OnionServiceNotRunning
77 | EK::OnionServiceProtocolViolation => SC::SERVICE_UNAVAILABLE,
78
79 EK::RemoteConnectionRefused
80 | EK::RemoteHostNotFound
81 | EK::RemoteHostResolutionFailed
82 | EK::RemoteStreamClosed
83 | EK::RemoteStreamError
84 | EK::RemoteStreamReset => SC::SERVICE_UNAVAILABLE,
85 }
88 }
89}