Fix: stop panic on TCP broken pipe

This commit is contained in:
Radhi Fadlillah 2019-08-06 08:27:39 +07:00
parent 3d12d6170b
commit 8ac455b307

View file

@ -11,11 +11,13 @@ import (
"io/ioutil" "io/ioutil"
"math" "math"
"mime" "mime"
"net"
"net/http" "net/http"
nurl "net/url" nurl "net/url"
"os" "os"
fp "path/filepath" fp "path/filepath"
"strings" "strings"
"syscall"
"time" "time"
"github.com/disintegration/imaging" "github.com/disintegration/imaging"
@ -183,7 +185,19 @@ func createTemplate(filename string, funcMap template.FuncMap) (*template.Templa
} }
func checkError(err error) { func checkError(err error) {
if err != nil { if err == nil {
panic(err) return
} }
// Check for a broken connection, as it is not really a
// condition that warrants a panic stack trace.
if ne, ok := err.(*net.OpError); ok {
if se, ok := ne.Err.(*os.SyscallError); ok {
if se.Err == syscall.EPIPE || se.Err == syscall.ECONNRESET {
return
}
}
}
panic(err)
} }