feat: ability to create a task #14
@ -12,8 +12,8 @@ pub enum ProjectCreateError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<ValidationErrors> for ErrorVec<ProjectCreateError> {
|
impl From<ValidationErrors> for ErrorVec<ProjectCreateError> {
|
||||||
fn from(e: ValidationErrors) -> Self {
|
fn from(validation_errors: ValidationErrors) -> Self {
|
||||||
e.errors()
|
validation_errors.errors()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|(&field, error_kind)| match field {
|
.flat_map(|(&field, error_kind)| match field {
|
||||||
"title" => match error_kind {
|
"title" => match error_kind {
|
||||||
@ -34,18 +34,18 @@ impl From<ValidationErrors> for ErrorVec<ProjectCreateError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// has to be implemented for Dioxus server functions
|
// Has to be implemented for Dioxus server functions.
|
||||||
impl Display for ProjectCreateError {
|
impl Display for ProjectCreateError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "{:?}", self)
|
write!(f, "{:?}", self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// has to be implemented for Dioxus server functions
|
// Has to be implemented for Dioxus server functions.
|
||||||
|
|||||||
impl FromStr for ProjectCreateError {
|
impl FromStr for ProjectCreateError {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(_: &str) -> Result<Self, Self::Err> {
|
fn from_str(_: &str) -> Result<Self, Self::Err> {
|
||||||
Ok(ProjectCreateError::TitleLengthInvalid)
|
Ok(ProjectCreateError::Error(Error::ServerInternal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ pub enum TaskCreateError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<ValidationErrors> for ErrorVec<TaskCreateError> {
|
impl From<ValidationErrors> for ErrorVec<TaskCreateError> {
|
||||||
fn from(e: ValidationErrors) -> Self {
|
fn from(validation_errors: ValidationErrors) -> Self {
|
||||||
e.errors()
|
validation_errors.errors()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|(&field, error_kind)| match field {
|
.flat_map(|(&field, error_kind)| match field {
|
||||||
"title" => match error_kind {
|
"title" => match error_kind {
|
||||||
@ -35,18 +35,18 @@ impl From<ValidationErrors> for ErrorVec<TaskCreateError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// has to be implemented for Dioxus server functions
|
// Has to be implemented for Dioxus server functions.
|
||||||
impl Display for TaskCreateError {
|
impl Display for TaskCreateError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "{:?}", self)
|
write!(f, "{:?}", self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// has to be implemented for Dioxus server functions
|
// Has to be implemented for Dioxus server functions.
|
||||||
impl FromStr for TaskCreateError {
|
impl FromStr for TaskCreateError {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(_: &str) -> Result<Self, Self::Err> {
|
fn from_str(_: &str) -> Result<Self, Self::Err> {
|
||||||
Ok(TaskCreateError::TitleLengthInvalid)
|
Ok(TaskCreateError::Error(Error::ServerInternal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user
Consider alternatives to panic for unexpected validation errors.
Using panic for unexpected validation errors may not be ideal in production code. Consider logging the error and returning a default error variant or using a custom error type.