Skip to content

Commit

Permalink
gateway: degrade error in gateway to log to reduce noise
Browse files Browse the repository at this point in the history
It logs all errors including expired IPNS keys and other non important
errors.

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
  • Loading branch information
Kubuxu authored and Lars Gierth committed Nov 16, 2016
1 parent 1a365a8 commit 82d46a5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"time"

core "github.com/ipfs/go-ipfs/core"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/importer"
chunk "github.com/ipfs/go-ipfs/importer/chunk"
dag "github.com/ipfs/go-ipfs/merkledag"
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"

coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/namesys"
path "github.com/ipfs/go-ipfs/path"
ft "github.com/ipfs/go-ipfs/unixfs"

Expand Down Expand Up @@ -166,6 +166,11 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprint(w, "Could not resolve path. Node is in offline mode.")
return
} else if err == namesys.ErrResolveFailed {
// Don't log that error as it is just noise
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "Path Resolve error: %s", err.Error())
return
} else if err != nil {
webError(w, "Path Resolve error", err, http.StatusBadRequest)
return
Expand Down Expand Up @@ -531,7 +536,8 @@ func webError(w http.ResponseWriter, message string, err error, defaultCode int)

func webErrorWithCode(w http.ResponseWriter, message string, err error, code int) {
w.WriteHeader(code)
log.Errorf("%s: %s", message, err) // TODO(cryptix): log errors until we have a better way to expose these (counter metrics maybe)

log.Errorf("%s: %s", message, err) // TODO(cryptix): log until we have a better way to expose these (counter metrics maybe)
fmt.Fprintf(w, "%s: %s", message, err)
}

Expand Down

0 comments on commit 82d46a5

Please sign in to comment.