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
//! Library erros.
use base64;
use iron::IronError;
use iron::status;
use std::io;
use tera;
quick_error!{
/// Container for errors that might happen during processing requests.
#[derive(Debug)]
pub enum Error {
/// Input/output error.
Io(err: io::Error) {
from()
cause(err)
}
/// Data limit exceeded.
TooBig {
description("Too large paste")
}
/// Malformed URI (no ID).
NoIdSegment {
description("ID segment not found in the URL")
}
/// Unknown ID.
IdNotFound(id: u64) {
description("ID not found")
display("Id {} not found", id)
}
/// ID decoder error.
IdDecode(err: base64::DecodeError) {
from()
cause(err)
}
/// Tera rendering error.
Tera(err: tera::Error) {
from()
cause(err)
}
/// URL parsing error.
Url(err: String) {
description("Can't parse URL")
display("Can't parse URL: {}", err)
}
/// We expect a `ContentLength` header for incoming requests.
NoContentLength {
description("No content-length header provided")
}
}
}
impl From<Error> for IronError {
fn from(err: Error) -> IronError {
match err {
e @ Error::IdNotFound(_) => IronError::new(e, status::NotFound),
e @ Error::TooBig => IronError::new(e, status::PayloadTooLarge),
e => IronError::new(e, status::BadRequest),
}
}
}