graphql_starter/pagination/
error.rs

1use error_info::ErrorInfo;
2use http::StatusCode;
3
4/// Error codes when using pagination
5#[derive(Debug, ErrorInfo)]
6#[allow(clippy::enum_variant_names)]
7pub enum PaginationErrorCode {
8    #[error(status=StatusCode::BAD_REQUEST, message = "Missing pagination data: at least one of \"first\" or \"last\" must be set")]
9    PageMissing,
10    #[error(status=StatusCode::BAD_REQUEST, message = "The \"{field}\" parameter must be a non-negative number")]
11    PageNegativeInput { field: &'static str },
12    #[error(status=StatusCode::BAD_REQUEST, message = "The \"{field}\" parameter can't exceed {max}")]
13    PageExceedsLimit { field: &'static str, max: usize },
14    #[error(status=StatusCode::BAD_REQUEST, message = "The \"first\" and \"last\" parameters cannot exist at the same time")]
15    PageFirstAndLast,
16    #[error(status=StatusCode::BAD_REQUEST, message = "The \"after\" and \"before\" parameters cannot exist at the same time")]
17    PageAfterAndBefore,
18    #[error(status=StatusCode::BAD_REQUEST, message = "When forward paginating only \"after\" is allowed, not \"before\"")]
19    PageForwardWithBefore,
20    #[error(status=StatusCode::BAD_REQUEST, message = "When backward paginating only \"before\" is allowed, not \"after\"")]
21    PageBackwardWithAfter,
22    #[error(status=StatusCode::BAD_REQUEST, message = "The provided cursor is not recognized")]
23    PageInvalidCursor,
24}