use std::error::Error;
use std::fmt;
use laravel::errors::Status;
#[derive(Debug, Clone, PartialEq, Eq, Status)]
#[status(422)]
#[non_exhaustive]
pub enum CommentError {
EmptyBody,
BodyTooLong {
max: usize,
},
InvalidGuest,
RepliesDisabled,
Deleted {
id: i64,
},
NotApproved {
id: i64,
},
UnknownReaction {
reaction: String,
},
NotFound {
id: i64,
},
}
impl fmt::Display for CommentError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EmptyBody => f.write_str("A comment can't be empty."),
Self::BodyTooLong { max } => write!(f, "A comment can't be longer than {max} characters."),
Self::InvalidGuest => f.write_str("A guest's comment needs a name and an email address."),
Self::RepliesDisabled => f.write_str("Replies are turned off."),
Self::Deleted { id } => write!(f, "The comment `{id}` was removed."),
Self::NotApproved { id } => write!(f, "The comment `{id}` isn't approved."),
Self::UnknownReaction { reaction } => write!(f, "`{reaction}` isn't an allowed reaction."),
Self::NotFound { id } => write!(f, "The comment `{id}` no longer exists."),
}
}
}
impl Error for CommentError {}