From 35983b480ad73d09101d2a2ba32da0d672e8412f Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Sat, 8 Nov 2014 21:41:57 -0800 Subject: [PATCH] cmd/ipfs2: Made '/ipfs' handler return more accurate HTTP response codes, resolves #287 --- cmd/ipfs2/ipfsHandler.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/ipfs2/ipfsHandler.go b/cmd/ipfs2/ipfsHandler.go index 46336026b..b522607b0 100644 --- a/cmd/ipfs2/ipfsHandler.go +++ b/cmd/ipfs2/ipfsHandler.go @@ -4,11 +4,13 @@ import ( "io" "net/http" + "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" core "github.com/jbenet/go-ipfs/core" "github.com/jbenet/go-ipfs/importer" dag "github.com/jbenet/go-ipfs/merkledag" + "github.com/jbenet/go-ipfs/routing" uio "github.com/jbenet/go-ipfs/unixfs/io" u "github.com/jbenet/go-ipfs/util" ) @@ -45,7 +47,14 @@ func (i *ipfsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { nd, err := i.ResolvePath(path) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + if err == routing.ErrNotFound { + w.WriteHeader(http.StatusNotFound) + } else if err == context.DeadlineExceeded { + w.WriteHeader(http.StatusRequestTimeout) + } else { + w.WriteHeader(http.StatusBadRequest) + } + log.Error(err) w.Write([]byte(err.Error())) return