From dc5cce23e9b0869455f546d968052bc200dd0011 Mon Sep 17 00:00:00 2001 From: Benjamin Morrison Date: Tue, 20 Jun 2023 23:29:12 -0400 Subject: init --- src/err.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/err.rs (limited to 'src/err.rs') diff --git a/src/err.rs b/src/err.rs new file mode 100644 index 0000000..6c178bd --- /dev/null +++ b/src/err.rs @@ -0,0 +1,51 @@ +/* Copyright (C) 2023 Ben Morrison + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +use crate::response; +use std::error::Error; +use std::fmt::Formatter; + +#[derive(Clone, Debug)] +pub struct Supernova { + message: String, + code: response::Code, +} + +impl Error for Supernova {} + +impl Supernova { + pub fn boom(message: &str) -> Supernova { + Supernova { + message: message.into(), + code: response::Code::Unknown, + } + } + + pub fn code(&self) -> response::Code { + self.code + } + + pub fn with_code(&mut self, code: response::Code) -> Supernova { + self.code = code; + self.clone() + } +} + +impl std::fmt::Display for Supernova { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", &self.message) + } +} -- cgit 1.4.1