summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index 649021e..3ccb73c 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -10,6 +10,7 @@ use iron::modifiers::Header;
pub enum LinoError {
DbError(rusqlite::Error),
NotFound(String),
+ BadRequest(String),
}
pub type Result<T> = std::result::Result<T, LinoError>;
@@ -19,6 +20,7 @@ impl fmt::Display for LinoError {
match *self {
LinoError::DbError(ref err) => err.fmt(f),
LinoError::NotFound(ref x) => write!(f, "Could not find {}", x),
+ LinoError::BadRequest(ref x) => write!(f, "Bad request: {}", x),
}
}
}
@@ -28,6 +30,7 @@ impl std::error::Error for LinoError {
match *self {
LinoError::DbError(ref err) => err.description(),
LinoError::NotFound(_) => "not found",
+ LinoError::BadRequest(_) => "bad request",
}
}
@@ -35,6 +38,7 @@ impl std::error::Error for LinoError {
match *self {
LinoError::DbError(ref err) => Some(err),
LinoError::NotFound(_) => None,
+ LinoError::BadRequest(_) => None,
}
}
}
@@ -49,6 +53,7 @@ impl From<LinoError> for IronError {
fn from(err: LinoError) -> IronError {
let code = match err {
LinoError::NotFound(_) => status::NotFound,
+ LinoError::BadRequest(_) => status::BadRequest,
_ => status::InternalServerError,
};
let description = format!("{:?}", err);