Skip to content

Commit

Permalink
feat: return 500 for all /ip[nf]s/id failures
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Feb 27, 2023
1 parent 1a8efbc commit 067e56f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 2 additions & 0 deletions gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,11 @@ func TestGatewayGet(t *testing.T) {
}{
{"127.0.0.1:8080", "/", http.StatusNotFound, "404 page not found\n"},
{"127.0.0.1:8080", "/" + k.Cid().String(), http.StatusNotFound, "404 page not found\n"},
{"127.0.0.1:8080", "/ipfs/this-is-not-a-cid", http.StatusInternalServerError, "failed to resolve /ipfs/this-is-not-a-cid: invalid path \"/ipfs/this-is-not-a-cid\": invalid CID: illegal base32 data at input byte 3\n"},
{"127.0.0.1:8080", k.String(), http.StatusOK, "fnord"},
{"127.0.0.1:8080", "/ipns/nxdomain.example.com", http.StatusInternalServerError, "failed to resolve /ipns/nxdomain.example.com: " + namesys.ErrResolveFailed.Error() + "\n"},
{"127.0.0.1:8080", "/ipns/%0D%0A%0D%0Ahello", http.StatusInternalServerError, "failed to resolve /ipns/\\r\\n\\r\\nhello: " + namesys.ErrResolveFailed.Error() + "\n"},
{"127.0.0.1:8080", "/ipns/k51qzi5uqu5djucgtwlxrbfiyfez1nb0ct58q5s4owg6se02evza05dfgi6tw5", http.StatusInternalServerError, "failed to resolve /ipns/k51qzi5uqu5djucgtwlxrbfiyfez1nb0ct58q5s4owg6se02evza05dfgi6tw5: " + namesys.ErrResolveFailed.Error() + "\n"},
{"127.0.0.1:8080", "/ipns/example.com", http.StatusOK, "fnord"},
{"example.com", "/", http.StatusOK, "fnord"},

Expand Down
3 changes: 0 additions & 3 deletions gateway/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log"
"github.com/ipfs/go-namesys"
"github.com/ipfs/go-path"
"github.com/ipfs/go-path/resolver"
coreiface "github.com/ipfs/interface-go-ipfs-core"
ipath "github.com/ipfs/interface-go-ipfs-core/path"
Expand Down Expand Up @@ -563,8 +562,6 @@ func webRequestError(w http.ResponseWriter, err *requestError) {

func webError(w http.ResponseWriter, err error, defaultCode int) {
switch {
case errors.Is(err, path.ErrInvalidPath{}):
webErrorWithCode(w, err, http.StatusBadRequest)
case isErrNotFound(err):
webErrorWithCode(w, err, http.StatusNotFound)
case errors.Is(err, ErrGatewayTimeout):
Expand Down
4 changes: 2 additions & 2 deletions gateway/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (api *errorMockAPI) ResolvePath(ctx context.Context, ip ipath.Path) (ipath.
return nil, api.err
}

func TestGatewayBadRequestInvalidPath(t *testing.T) {
func TestGatewayInternalServerErrorInvalidPath(t *testing.T) {
api, _ := newMockAPI(t)
ts := newTestServer(t, api)
t.Logf("test server url: %s", ts.URL)
Expand All @@ -82,7 +82,7 @@ func TestGatewayBadRequestInvalidPath(t *testing.T) {
res, err := ts.Client().Do(req)
assert.Nil(t, err)

assert.Equal(t, http.StatusBadRequest, res.StatusCode)
assert.Equal(t, http.StatusInternalServerError, res.StatusCode)
}

func TestGatewayTimeoutBubblingFromAPI(t *testing.T) {
Expand Down

0 comments on commit 067e56f

Please sign in to comment.