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
49 lines (37 loc) · 1.28 KB
/
error.rs
File metadata and controls
49 lines (37 loc) · 1.28 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
use thiserror::Error;
use crate::tracker::torrent;
#[derive(Error, Debug)]
pub enum Error {
#[error("internal server error")]
InternalServer,
#[error("info_hash is either missing or invalid")]
InvalidInfoHash,
#[error("connection id could not be verified")]
InvalidConnectionId,
#[error("could not find remote address")]
AddressNotFound,
#[error("torrent has no peers")]
NoPeersFound,
#[error("torrent not on whitelist")]
TorrentNotWhitelisted,
#[error("peer not authenticated")]
PeerNotAuthenticated,
#[error("invalid authentication key")]
PeerKeyNotValid,
#[error("exceeded info_hash limit")]
ExceededInfoHashLimit,
#[error("bad request")]
BadRequest,
}
impl From<torrent::Error> for Error {
fn from(e: torrent::Error) -> Self {
match e {
torrent::Error::TorrentNotWhitelisted => Error::TorrentNotWhitelisted,
torrent::Error::PeerNotAuthenticated => Error::PeerNotAuthenticated,
torrent::Error::PeerKeyNotValid => Error::PeerKeyNotValid,
torrent::Error::NoPeersFound => Error::NoPeersFound,
torrent::Error::CouldNotSendResponse => Error::InternalServer,
torrent::Error::InvalidInfoHash => Error::InvalidInfoHash,
}
}
}