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
import "errors"
var (
ErrPageOutOfRange = errors.New("requested page out of range")
)
type Pagination struct {
Page *int `json:"page"`
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) {
return fmt.Errorf("requested page out of range")
return common.ErrPageOutOfRange
}
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
}
if offset > int32(count) {
return common.ErrPageOutOfRange
}
rows, err = db.ListIncidentsP(ctx, dbParam)
return err
}, pgx.TxOptions{})

View file

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