From 82d46a5b5be372a4c0171d41de77992e175c4547 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Fri, 15 Jul 2016 12:31:02 +0100 Subject: [PATCH] gateway: degrade error in gateway to log to reduce noise It logs all errors including expired IPNS keys and other non important errors. License: MIT Signed-off-by: Jakub Sztandera --- core/corehttp/gateway_handler.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index 3bfa74b42..2c6302fb8 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -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" @@ -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 @@ -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) }