Skip to content

Commit

Permalink
fix: correct error messages for http handler
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Aug 17, 2023
1 parent 6dd25a2 commit 72701c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/server/http/ipfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ func TestIpfsHandler(t *testing.T) {
wantStatus: http.StatusBadRequest,
wantBody: "invalid providers parameter\n",
},
{
name: "400 on invalid entity-bytes query parameter",
method: "GET",
path: "/ipfs/bafybeic56z3yccnla3cutmvqsn5zy3g24muupcsjtoyp3pu5pm5amurjx4?entity-bytes=invalid",
headers: map[string]string{"Accept": "application/vnd.ipld.car"},
wantStatus: http.StatusBadRequest,
wantBody: "invalid entity-bytes parameter\n",
},
{
name: "404 when no candidates can be found",
method: "GET",
Expand Down
8 changes: 6 additions & 2 deletions pkg/server/http/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import (
// parameter is not one of the supported values.
func ParseScope(req *http.Request) (types.DagScope, error) {
if req.URL.Query().Has("dag-scope") {
return types.ParseDagScope(req.URL.Query().Get("dag-scope"))
if ds, err := types.ParseDagScope(req.URL.Query().Get("dag-scope")); err != nil {
return ds, errors.New("invalid dag-scope parameter")
} else {
return ds, nil
}
}
// check for legacy param name -- to do -- delete once we confirm this isn't used any more
if req.URL.Query().Has("car-scope") {
Expand All @@ -39,7 +43,7 @@ func ParseByteRange(req *http.Request) (*types.ByteRange, error) {
if req.URL.Query().Has("entity-bytes") {
br, err := types.ParseByteRange(req.URL.Query().Get("entity-bytes"))
if err != nil {
return nil, err
return nil, errors.New("invalid entity-bytes parameter")
}
return &br, nil
}
Expand Down

0 comments on commit 72701c1

Please sign in to comment.