Add serde and internal error

This commit is contained in:
Valentin Brandl 2019-04-19 22:11:03 +02:00
parent 94c97fc9b1
commit f7b2da2b5a
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D

View File

@ -2,19 +2,23 @@ use actix_web::{HttpResponse, ResponseError};
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum Error { pub(crate) enum Error {
Git(git2::Error),
Io(std::io::Error),
Badge(String), Badge(String),
Git(git2::Error),
Internal,
Io(std::io::Error),
ParseColor, ParseColor,
Serial(serde_json::Error),
} }
impl std::fmt::Display for Error { impl std::fmt::Display for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
Error::Git(e) => write!(fmt, "Git({})", e),
Error::Io(e) => write!(fmt, "Io({})", e),
Error::Badge(s) => write!(fmt, "Badge({})", s), Error::Badge(s) => write!(fmt, "Badge({})", s),
Error::Git(e) => write!(fmt, "Git({})", e),
Error::Internal => write!(fmt, "Internal Error"),
Error::Io(e) => write!(fmt, "Io({})", e),
Error::ParseColor => write!(fmt, "Parse error"), Error::ParseColor => write!(fmt, "Parse error"),
Error::Serial(e) => write!(fmt, "Serial({})", e),
} }
} }
} }
@ -44,3 +48,9 @@ impl From<std::io::Error> for Error {
Error::Io(err) Error::Io(err)
} }
} }
impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Self {
Error::Serial(err)
}
}