Error text

This commit is contained in:
Daniel Ponte 2024-12-29 15:24:40 -05:00
parent 82d2d5c340
commit 6acae39cba
4 changed files with 13 additions and 1 deletions

View file

@ -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"`

View file

@ -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)

View file

@ -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{})

View file

@ -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 {