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 <kubuxu@protonmail.ch>
Jakub Sztandera committed
Jul 15, 2016 at 12:31 UTC
82d46a5b5be372a4c0171d41de77992e175c4547
1 file changed
+9
-3
core/corehttp/gateway_handler.go
+9
-3
@@ -12,12 +12,12 @@ import (
12
"time"
13
14
core "github.com/ipfs/go-ipfs/core"
15
+ coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
16
"github.com/ipfs/go-ipfs/importer"
17
chunk "github.com/ipfs/go-ipfs/importer/chunk"
18
dag "github.com/ipfs/go-ipfs/merkledag"
19
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
19
-
20
- coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
20
+ "github.com/ipfs/go-ipfs/namesys"
21
path "github.com/ipfs/go-ipfs/path"
22
ft "github.com/ipfs/go-ipfs/unixfs"
23
@@ -166,6 +166,11 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
166
w.WriteHeader(http.StatusServiceUnavailable)
167
fmt.Fprint(w, "Could not resolve path. Node is in offline mode.")
168
return
169
+ } else if err == namesys.ErrResolveFailed {
170
+ // Don't log that error as it is just noise
171
+ w.WriteHeader(http.StatusBadRequest)
172
+ fmt.Fprintf(w, "Path Resolve error: %s", err.Error())
173
+ return
174
} else if err != nil {
175
webError(w, "Path Resolve error", err, http.StatusBadRequest)
176
return
@@ -531,7 +536,8 @@ func webError(w http.ResponseWriter, message string, err error, defaultCode int)
536
537
func webErrorWithCode(w http.ResponseWriter, message string, err error, code int) {
538
w.WriteHeader(code)
534
- log.Errorf("%s: %s", message, err) // TODO(cryptix): log errors until we have a better way to expose these (counter metrics maybe)
539
+
540
+ log.Errorf("%s: %s", message, err) // TODO(cryptix): log until we have a better way to expose these (counter metrics maybe)
541
fmt.Fprintf(w, "%s: %s", message, err)
542
}
543