refactor: make the serverside error handling more robust

This commit is contained in:
2024-08-18 19:09:40 +02:00
parent ad70b5cfa8
commit f0f24d33ba
12 changed files with 301 additions and 43 deletions

29
src/errors/error.rs Normal file
View File

@ -0,0 +1,29 @@
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use std::str::FromStr;
#[derive(Serialize, Deserialize, Debug)]
pub enum Error {
ServerInternal,
}
// has to be implemented for Dioxus server functions
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::ServerInternal => write!(f, "internal server error"),
}
}
}
// has to be implemented for Dioxus server functions
impl FromStr for Error {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"internal server error" => Error::ServerInternal,
_ => return Err(()),
})
}
}