mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-30 19:51:58 +00:00
rpc: return err if page is incorrect (less than 0 or greater than tot… (#3825)
* rpc: return err if page is incorrect (less than 0 or greater than total pages) Fixes #3813 * fix rpc_test
This commit is contained in:
committed by
Jack Zampolin
parent
df6df61ea9
commit
e89991c445
@@ -1,6 +1,7 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
@@ -145,19 +146,24 @@ func SetConfig(c cfg.RPCConfig) {
|
||||
config = c
|
||||
}
|
||||
|
||||
func validatePage(page, perPage, totalCount int) int {
|
||||
func validatePage(page, perPage, totalCount int) (int, error) {
|
||||
if perPage < 1 {
|
||||
return 1
|
||||
panic(fmt.Sprintf("zero or negative perPage: %d", perPage))
|
||||
}
|
||||
|
||||
if page == 0 {
|
||||
return 1, nil // default
|
||||
}
|
||||
|
||||
pages := ((totalCount - 1) / perPage) + 1
|
||||
if page < 1 {
|
||||
page = 1
|
||||
} else if page > pages {
|
||||
page = pages
|
||||
if pages == 0 {
|
||||
pages = 1 // one page (even if it's empty)
|
||||
}
|
||||
if page < 0 || page > pages {
|
||||
return 1, fmt.Errorf("page should be within [0, %d] range, given %d", pages, page)
|
||||
}
|
||||
|
||||
return page
|
||||
return page, nil
|
||||
}
|
||||
|
||||
func validatePerPage(perPage int) int {
|
||||
|
Reference in New Issue
Block a user