diff options
author | Benjamin Morrison <ben@gbmor.org> | 2023-06-20 23:29:12 -0400 |
---|---|---|
committer | Benjamin Morrison <ben@gbmor.org> | 2023-06-20 23:30:17 -0400 |
commit | dc5cce23e9b0869455f546d968052bc200dd0011 (patch) | |
tree | bb3754de4483b4a50edc8a6a3d4585f305e4d1e2 /src/err.rs | |
download | laika-dc5cce23e9b0869455f546d968052bc200dd0011.tar.gz |
init
Diffstat (limited to 'src/err.rs')
-rw-r--r-- | src/err.rs | 51 |
1 files changed, 51 insertions, 0 deletions
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 <ben@gbmor.org> + * + * 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 <https: *www.gnu.org/licenses/>. + */ + +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) + } +} |