chore: bridge gap between core/result and quark

This commit is contained in:
Paul Makles
2023-04-22 17:56:09 +01:00
parent 11a87263be
commit bbe1f4936c
2 changed files with 20 additions and 5 deletions

View File

@@ -89,3 +89,6 @@ authifier = { version = "1.0.7", features = [ "async-std-runtime" ] }
# Sentry # Sentry
sentry = "0.25.0" sentry = "0.25.0"
# Core
revolt-result = { path = "../core/result", features = [ "serde", "schemas" ] }

View File

@@ -19,6 +19,12 @@ pub enum Error {
/// This error was not labeled :( /// This error was not labeled :(
LabelMe, LabelMe,
/// Core crate error
Core {
#[serde(flatten)]
error: revolt_result::Error,
},
// ? Onboarding related errors // ? Onboarding related errors
AlreadyOnboarded, AlreadyOnboarded,
@@ -39,13 +45,13 @@ pub enum Error {
CannotEditMessage, CannotEditMessage,
CannotJoinCall, CannotJoinCall,
TooManyAttachments { TooManyAttachments {
max: usize max: usize,
}, },
TooManyReplies { TooManyReplies {
max: usize max: usize,
}, },
TooManyChannels { TooManyChannels {
max: usize max: usize,
}, },
EmptyMessage, EmptyMessage,
PayloadTooLarge, PayloadTooLarge,
@@ -64,10 +70,10 @@ pub enum Error {
max: usize, max: usize,
}, },
TooManyEmoji { TooManyEmoji {
max: usize max: usize,
}, },
TooManyRoles { TooManyRoles {
max: usize max: usize,
}, },
// ? Bot related errors // ? Bot related errors
@@ -135,6 +141,11 @@ impl Error {
error: validation_error, error: validation_error,
}) })
} }
/// Create a error from core error
pub fn from_core(error: revolt_result::Error) -> Error {
Error::Core { error }
}
} }
/// Result type with custom Error /// Result type with custom Error
@@ -145,6 +156,7 @@ impl<'r> Responder<'r, 'static> for Error {
fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> { fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> {
let status = match self { let status = match self {
Error::LabelMe => Status::InternalServerError, Error::LabelMe => Status::InternalServerError,
Error::Core { .. } => Status::InternalServerError,
Error::AlreadyOnboarded => Status::Forbidden, Error::AlreadyOnboarded => Status::Forbidden,