add golgi dependency and error variant

This commit is contained in:
glyph 2022-02-11 10:31:31 +02:00
parent a174027ff5
commit 17ea3e7f44
2 changed files with 11 additions and 0 deletions

View File

@ -36,6 +36,7 @@ maintenance = { status = "actively-developed" }
[dependencies]
env_logger = "0.8"
golgi = { path = "../../../playground/rust/golgi" }
lazy_static = "1.4.0"
log = "0.4"
nest = "1.0.0"

View File

@ -1,5 +1,6 @@
//! Custom error type representing all possible error variants for peach-web.
use golgi::GolgiError;
use peach_lib::error::PeachError;
use peach_lib::{serde_json, serde_yaml};
use serde_json::error::Error as JsonError;
@ -8,6 +9,7 @@ use serde_yaml::Error as YamlError;
/// Custom error type encapsulating all possible errors for the web application.
#[derive(Debug)]
pub enum PeachWebError {
Golgi(GolgiError),
Json(JsonError),
Yaml(YamlError),
FailedToRegisterDynDomain(String),
@ -17,6 +19,7 @@ pub enum PeachWebError {
impl std::error::Error for PeachWebError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
PeachWebError::Golgi(ref source) => Some(source),
PeachWebError::Json(ref source) => Some(source),
PeachWebError::Yaml(ref source) => Some(source),
PeachWebError::FailedToRegisterDynDomain(_) => None,
@ -28,6 +31,7 @@ impl std::error::Error for PeachWebError {
impl std::fmt::Display for PeachWebError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
PeachWebError::Golgi(ref source) => write!(f, "Golgi error: {}", source),
PeachWebError::Json(ref source) => write!(f, "Serde JSON error: {}", source),
PeachWebError::Yaml(ref source) => write!(f, "Serde YAML error: {}", source),
PeachWebError::FailedToRegisterDynDomain(ref msg) => {
@ -38,6 +42,12 @@ impl std::fmt::Display for PeachWebError {
}
}
impl From<GolgiError> for PeachWebError {
fn from(err: GolgiError) -> PeachWebError {
PeachWebError::Golgi(err)
}
}
impl From<JsonError> for PeachWebError {
fn from(err: JsonError) -> PeachWebError {
PeachWebError::Json(err)