forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
68 lines (57 loc) · 2.25 KB
/
error.rs
File metadata and controls
68 lines (57 loc) · 2.25 KB
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
//! Error types for the UDP server.
use std::panic::Location;
use aquatic_udp_protocol::{ConnectionId, RequestParseError};
use bittorrent_udp_tracker_core::services::announce::UdpAnnounceError;
use bittorrent_udp_tracker_core::services::scrape::UdpScrapeError;
use derive_more::derive::Display;
use thiserror::Error;
use torrust_tracker_located_error::LocatedError;
#[derive(Display, Debug)]
#[display(":?")]
pub struct ConnectionCookie(pub ConnectionId);
/// Error returned by the UDP server.
#[derive(Error, Debug)]
pub enum Error {
/// Error returned when the request is invalid.
#[error("error when phrasing request: {request_parse_error:?}")]
RequestParseError { request_parse_error: RequestParseError },
/// Error returned when the domain tracker returns an announce error.
#[error("tracker announce error: {source}")]
UdpAnnounceError { source: UdpAnnounceError },
/// Error returned when the domain tracker returns an scrape error.
#[error("tracker scrape error: {source}")]
UdpScrapeError { source: UdpScrapeError },
/// Error returned from a third-party library (`aquatic_udp_protocol`).
#[error("internal server error: {message}, {location}")]
InternalServer {
location: &'static Location<'static>,
message: String,
},
/// Error returned when the request is invalid.
#[error("bad request: {source}")]
BadRequest {
source: LocatedError<'static, dyn std::error::Error + Send + Sync>,
},
/// Error returned when tracker requires authentication.
#[error("domain tracker requires authentication but is not supported in current UDP implementation. Location: {location}")]
TrackerAuthenticationRequired { location: &'static Location<'static> },
}
impl From<RequestParseError> for Error {
fn from(request_parse_error: RequestParseError) -> Self {
Self::RequestParseError { request_parse_error }
}
}
impl From<UdpAnnounceError> for Error {
fn from(udp_announce_error: UdpAnnounceError) -> Self {
Self::UdpAnnounceError {
source: udp_announce_error,
}
}
}
impl From<UdpScrapeError> for Error {
fn from(udp_scrape_error: UdpScrapeError) -> Self {
Self::UdpScrapeError {
source: udp_scrape_error,
}
}
}