From 6acae39cba63629565c251a7035ae57acbd5b414 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 29 Dec 2024 15:24:40 -0500 Subject: [PATCH] Error text --- internal/common/pagination.go | 6 ++++++ pkg/calls/callstore/store.go | 2 +- pkg/incidents/incstore/store.go | 4 ++++ pkg/rest/api.go | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/common/pagination.go b/internal/common/pagination.go index aacdf7d..09eb7f9 100644 --- a/internal/common/pagination.go +++ b/internal/common/pagination.go @@ -1,5 +1,11 @@ package common +import "errors" + +var ( + ErrPageOutOfRange = errors.New("requested page out of range") +) + type Pagination struct { Page *int `json:"page"` PerPage *int `json:"perPage"` diff --git a/pkg/calls/callstore/store.go b/pkg/calls/callstore/store.go index fbbde6d..10c1c9d 100644 --- a/pkg/calls/callstore/store.go +++ b/pkg/calls/callstore/store.go @@ -115,7 +115,7 @@ func (s *store) Calls(ctx context.Context, p CallsParams) (rows []database.ListC } if offset > int32(count) { - return fmt.Errorf("requested page out of range") + return common.ErrPageOutOfRange } rows, err = db.ListCallsP(ctx, par) diff --git a/pkg/incidents/incstore/store.go b/pkg/incidents/incstore/store.go index 3bc0339..6772e12 100644 --- a/pkg/incidents/incstore/store.go +++ b/pkg/incidents/incstore/store.go @@ -133,6 +133,10 @@ func (s *store) Incidents(ctx context.Context, p IncidentsParams) (rows []databa return err } + if offset > int32(count) { + return common.ErrPageOutOfRange + } + rows, err = db.ListIncidentsP(ctx, dbParam) return err }, pgx.TxOptions{}) diff --git a/pkg/rest/api.go b/pkg/rest/api.go index 6f0c40b..50bed21 100644 --- a/pkg/rest/api.go +++ b/pkg/rest/api.go @@ -5,6 +5,7 @@ import ( "net/http" "net/url" + "dynatron.me/x/stillbox/internal/common" "dynatron.me/x/stillbox/pkg/talkgroups/tgstore" "github.com/go-chi/chi/v5" @@ -128,6 +129,7 @@ var statusMapping = map[error]errResponder{ tgstore.ErrReference: constraintErrText, ErrBadUID: unauthErrText, ErrBadAppName: unauthErrText, + common.ErrPageOutOfRange: badRequestErrText, } func autoError(err error) render.Renderer {