Error text
This commit is contained in:
parent
82d2d5c340
commit
6acae39cba
4 changed files with 13 additions and 1 deletions
|
@ -1,5 +1,11 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrPageOutOfRange = errors.New("requested page out of range")
|
||||||
|
)
|
||||||
|
|
||||||
type Pagination struct {
|
type Pagination struct {
|
||||||
Page *int `json:"page"`
|
Page *int `json:"page"`
|
||||||
PerPage *int `json:"perPage"`
|
PerPage *int `json:"perPage"`
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (s *store) Calls(ctx context.Context, p CallsParams) (rows []database.ListC
|
||||||
}
|
}
|
||||||
|
|
||||||
if offset > int32(count) {
|
if offset > int32(count) {
|
||||||
return fmt.Errorf("requested page out of range")
|
return common.ErrPageOutOfRange
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err = db.ListCallsP(ctx, par)
|
rows, err = db.ListCallsP(ctx, par)
|
||||||
|
|
|
@ -133,6 +133,10 @@ func (s *store) Incidents(ctx context.Context, p IncidentsParams) (rows []databa
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if offset > int32(count) {
|
||||||
|
return common.ErrPageOutOfRange
|
||||||
|
}
|
||||||
|
|
||||||
rows, err = db.ListIncidentsP(ctx, dbParam)
|
rows, err = db.ListIncidentsP(ctx, dbParam)
|
||||||
return err
|
return err
|
||||||
}, pgx.TxOptions{})
|
}, pgx.TxOptions{})
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"dynatron.me/x/stillbox/internal/common"
|
||||||
"dynatron.me/x/stillbox/pkg/talkgroups/tgstore"
|
"dynatron.me/x/stillbox/pkg/talkgroups/tgstore"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
@ -128,6 +129,7 @@ var statusMapping = map[error]errResponder{
|
||||||
tgstore.ErrReference: constraintErrText,
|
tgstore.ErrReference: constraintErrText,
|
||||||
ErrBadUID: unauthErrText,
|
ErrBadUID: unauthErrText,
|
||||||
ErrBadAppName: unauthErrText,
|
ErrBadAppName: unauthErrText,
|
||||||
|
common.ErrPageOutOfRange: badRequestErrText,
|
||||||
}
|
}
|
||||||
|
|
||||||
func autoError(err error) render.Renderer {
|
func autoError(err error) render.Renderer {
|
||||||
|
|
Loading…
Reference in a new issue