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"
"math"
"mime"
"net"
"net/http"
nurl "net/url"
"os"
fp "path/filepath"
"strings"
"syscall"
"time"
"github.com/disintegration/imaging"
@ -183,7 +185,19 @@ func createTemplate(filename string, funcMap template.FuncMap) (*template.Templa
}
func checkError(err error) {
if err != nil {
panic(err)
if err == nil {
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)
}