use base64;
use iron::IronError;
use iron::status;
use std::io;
use tera;
quick_error!{
#[derive(Debug)]
pub enum Error {
Io(err: io::Error) {
from()
cause(err)
}
TooBig {
description("Too large paste")
}
NoIdSegment {
description("ID segment not found in the URL")
}
IdNotFound(id: u64) {
description("ID not found")
display("Id {} not found", id)
}
IdDecode(err: base64::DecodeError) {
from()
cause(err)
}
Tera(err: tera::Error) {
from()
cause(err)
}
Url(err: String) {
description("Can't parse URL")
display("Can't parse URL: {}", err)
}
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),
}
}
}