Skip to content

Commit 11383c0

Browse files
committed
Switch two existing pagination error responses to Bad Request
Reviewing the source for cargo, it does not appear that there is any way to specify a `page` number and the `per_page` value is capped at 100 by cargo since at least 1.29. Showing a sub-optimal error message to very old versions of cargo seems okay.
1 parent b972560 commit 11383c0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/controllers/helpers/pagination.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::models::helpers::with_count::*;
2-
use crate::util::errors::*;
2+
use crate::util::errors::{bad_request, AppResult};
33
use diesel::pg::Pg;
44
use diesel::prelude::*;
55
use diesel::query_builder::*;
@@ -18,7 +18,7 @@ impl Page {
1818
if let Some(s) = params.get("page") {
1919
let numeric_page = s.parse().map_err(|e| bad_request(&e))?;
2020
if numeric_page < 1 {
21-
return Err(cargo_err(&format_args!(
21+
return Err(bad_request(&format_args!(
2222
"page indexing starts from 1, page {} is invalid",
2323
numeric_page,
2424
)));
@@ -48,7 +48,7 @@ impl PaginationOptions {
4848
.unwrap_or(Ok(DEFAULT_PER_PAGE))?;
4949

5050
if per_page > MAX_PER_PAGE {
51-
return Err(cargo_err(&format_args!(
51+
return Err(bad_request(&format_args!(
5252
"cannot request more than {} items",
5353
MAX_PER_PAGE,
5454
)));

0 commit comments

Comments
 (0)