From 1c8fcd9491c5a7415ecf67b8b9469c978a80f64b Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 2 Dec 2015 20:48:37 -0800 Subject: [PATCH] fixup panic catching in http handler funcs License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/kubo@8ad1141436dbb795e2b545378527e6f7ad96685e --- gateway/core/corehttp/gateway_handler.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gateway/core/corehttp/gateway_handler.go b/gateway/core/corehttp/gateway_handler.go index 509e751de..1cc172e50 100644 --- a/gateway/core/corehttp/gateway_handler.go +++ b/gateway/core/corehttp/gateway_handler.go @@ -6,6 +6,7 @@ import ( "io" "net/http" gopath "path" + "runtime/debug" "strings" "time" @@ -55,6 +56,14 @@ func (i *gatewayHandler) newDagFromReader(r io.Reader) (*dag.Node, error) { // TODO(btc): break this apart into separate handlers using a more expressive muxer func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + defer func() { + if r := recover(); r != nil { + log.Error("A panic occurred in the gateway handler!") + log.Error(r) + debug.PrintStack() + } + }() + if i.config.Writable { switch r.Method { case "POST":