diff options
author | cel 🌸 <cel@blos.sm> | 2023-02-15 18:08:23 +0000 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-02-15 18:08:23 +0000 |
commit | b8bbceb00be3ba01cd14a111f4dfc407880f493e (patch) | |
tree | a5a4897e10f992b70c05bb494c4eb3c1c09091e8 /src/error.rs | |
parent | fce07d2749f2e5fad3e4925919233d2f3796b684 (diff) | |
download | blossom-b8bbceb00be3ba01cd14a111f4dfc407880f493e.tar.gz blossom-b8bbceb00be3ba01cd14a111f4dfc407880f493e.tar.bz2 blossom-b8bbceb00be3ba01cd14a111f4dfc407880f493e.zip |
refactor rust into separate files and add proper error handling
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..38802d3 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,29 @@ +use rocket::Responder; + +#[derive(Responder, Debug)] +pub enum BlossomError { + #[response(status = 500)] + Reqwest(&'static str, #[response(ignore)] reqwest::Error), + #[response(status = 500)] + ListenBrainz(&'static str, #[response(ignore)] listenbrainz::Error), + #[response(status = 500)] + Skinnyverse(&'static str, #[response(ignore)] mastodon_async::Error), +} + +impl From<reqwest::Error> for BlossomError { + fn from(e: reqwest::Error) -> Self { + BlossomError::Reqwest("reqwest error", e) + } +} + +impl From<listenbrainz::Error> for BlossomError { + fn from(e: listenbrainz::Error) -> Self { + BlossomError::ListenBrainz("listenbrainz error", e) + } +} + +impl From<mastodon_async::Error> for BlossomError { + fn from(e: mastodon_async::Error) -> Self { + BlossomError::Skinnyverse("skinnyverse error", e) + } +} |