laravel_comments/
error.rs1use std::error::Error;
4use std::fmt;
5
6use laravel::errors::Status;
7
8#[derive(Debug, Clone, PartialEq, Eq, Status)]
10#[status(422)]
11#[non_exhaustive]
12pub enum CommentError {
13 EmptyBody,
15 BodyTooLong {
17 max: usize,
19 },
20 InvalidGuest,
22 RepliesDisabled,
24 Deleted {
26 id: i64,
28 },
29 NotApproved {
31 id: i64,
33 },
34 UnknownReaction {
36 reaction: String,
38 },
39 NotFound {
41 id: i64,
43 },
44}
45
46impl fmt::Display for CommentError {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 match self {
49 Self::EmptyBody => f.write_str("A comment can't be empty."),
50 Self::BodyTooLong { max } => write!(f, "A comment can't be longer than {max} characters."),
51 Self::InvalidGuest => f.write_str("A guest's comment needs a name and an email address."),
52 Self::RepliesDisabled => f.write_str("Replies are turned off."),
53 Self::Deleted { id } => write!(f, "The comment `{id}` was removed."),
54 Self::NotApproved { id } => write!(f, "The comment `{id}` isn't approved."),
55 Self::UnknownReaction { reaction } => write!(f, "`{reaction}` isn't an allowed reaction."),
56 Self::NotFound { id } => write!(f, "The comment `{id}` no longer exists."),
57 }
58 }
59}
60
61impl Error for CommentError {}