paginator_rs/
error.rs

1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug)]
5pub enum PaginatorError {
6    InvalidPage(u32),
7    InvalidPerPage(u32),
8    SerializationError(String),
9    Custom(String),
10}
11
12impl fmt::Display for PaginatorError {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            PaginatorError::InvalidPage(page) => {
16                write!(f, "Invalid page number: {}. Page must be >= 1", page)
17            }
18            PaginatorError::InvalidPerPage(per_page) => {
19                write!(
20                    f,
21                    "Invalid per_page value: {}. Must be between 1 and 100",
22                    per_page
23                )
24            }
25            PaginatorError::SerializationError(msg) => {
26                write!(f, "Serialization error: {}", msg)
27            }
28            PaginatorError::Custom(msg) => write!(f, "{}", msg),
29        }
30    }
31}
32
33impl Error for PaginatorError {}
34
35pub type PaginatorResult<T> = Result<T, PaginatorError>;