refactor: make the serverside error handling more robust
This commit is contained in:
29
src/errors/error.rs
Normal file
29
src/errors/error.rs
Normal 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(()),
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user