Skip to content

Commit a0bf643

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 a0bf643

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
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
)));

src/tests/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ fn following() {
296296
assert_eq!(r.meta.more, false);
297297

298298
user.get_with_query::<()>("/api/v1/me/updates", "page=0")
299-
.bad_with_status(200); // TODO: Should be 500
299+
.bad_with_status(400);
300300
}
301301

302302
#[test]

0 commit comments

Comments
 (0)