Skip to content

Commit

Permalink
Add limit to error response
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Jul 16, 2024
1 parent 6c62498 commit 493fd21
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion api/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package events

import (
"context"
"fmt"
"net/http"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -54,7 +55,7 @@ func (e *Events) handleFilter(w http.ResponseWriter, req *http.Request) error {
return utils.BadRequest(errors.WithMessage(err, "body"))
}
if filter.Options != nil && filter.Options.Limit > e.limit {
return utils.Forbidden(errors.New("options.limit exceeds the maximum allowed value"))
return utils.Forbidden(fmt.Errorf("options.limit exceeds the maximum allowed value of %d", e.limit))
}
if filter.Options == nil {
filter.Options = &logdb.Options{
Expand Down
2 changes: 1 addition & 1 deletion api/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestOption(t *testing.T) {
}

res, statusCode := httpPost(t, ts.URL+"/events", filter)
assert.Equal(t, "options.limit exceeds the maximum allowed value", strings.Trim(string(res), "\n"))
assert.Equal(t, "options.limit exceeds the maximum allowed value of 5", strings.Trim(string(res), "\n"))
assert.Equal(t, http.StatusForbidden, statusCode)

filter.Options.Limit = 5
Expand Down
3 changes: 2 additions & 1 deletion api/transfers/transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package transfers

import (
"context"
"fmt"
"net/http"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -60,7 +61,7 @@ func (t *Transfers) handleFilterTransferLogs(w http.ResponseWriter, req *http.Re
return utils.BadRequest(errors.WithMessage(err, "body"))
}
if filter.Options != nil && filter.Options.Limit > t.limit {
return utils.Forbidden(errors.New("options.limit exceeds the maximum allowed value"))
return utils.Forbidden(fmt.Errorf("options.limit exceeds the maximum allowed value of %d", t.limit))
}
if filter.Options == nil {
filter.Options = &logdb.Options{
Expand Down
2 changes: 1 addition & 1 deletion api/transfers/transfers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestOption(t *testing.T) {
}

res, statusCode := httpPost(t, ts.URL+"/transfers", filter)
assert.Equal(t, "options.limit exceeds the maximum allowed value", strings.Trim(string(res), "\n"))
assert.Equal(t, "options.limit exceeds the maximum allowed value of 5", strings.Trim(string(res), "\n"))
assert.Equal(t, http.StatusForbidden, statusCode)

filter.Options.Limit = 5
Expand Down

0 comments on commit 493fd21

Please sign in to comment.