Skip to content

Commit

Permalink
fix(gateway): ipld.ErrNotFound should result in a 404
Browse files Browse the repository at this point in the history
In case of blockstore restriction like with --offline or similar restriction, returning a 500 is inapropriate.

It's also going back to a previous gateway behavior (at least in kubo v0.22, possibly later).
  • Loading branch information
MichaelMure committed Mar 22, 2024
1 parent b101ba0 commit d088e1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gateway/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ipfs/boxo/gateway/assets"
"github.com/ipfs/boxo/path/resolver"
"github.com/ipfs/go-cid"
ipld "github.com/ipfs/go-ipld-format"
"github.com/ipld/go-ipld-prime/datamodel"
)

Expand Down Expand Up @@ -188,6 +189,10 @@ func isErrNotFound(err error) bool {
return true
}

if ipld.IsNotFound(err) {
return true
}

// Checks if err is of a type that does not implement the .Is interface and
// cannot be directly compared to. Therefore, errors.Is cannot be used.
for {
Expand Down
2 changes: 1 addition & 1 deletion gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ func TestErrorBubblingFromBackend(t *testing.T) {
})
}

testError("500 Not Found from IPLD", &ipld.ErrNotFound{}, http.StatusInternalServerError)
testError("404 Not Found from IPLD", &ipld.ErrNotFound{}, http.StatusNotFound)
testError("404 Not Found from path resolver", &resolver.ErrNoLink{}, http.StatusNotFound)
testError("502 Bad Gateway", ErrBadGateway, http.StatusBadGateway)
testError("504 Gateway Timeout", ErrGatewayTimeout, http.StatusGatewayTimeout)
Expand Down

0 comments on commit d088e1e

Please sign in to comment.