Commit d85d61c9 authored by Jeromy's avatar Jeromy

recover and print panics that happen in API server

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent 8c652907
......@@ -7,6 +7,8 @@ import (
"io"
"net/http"
"net/url"
"os"
"runtime"
"strconv"
"strings"
......@@ -103,6 +105,16 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Debug("Incoming API request: ", r.URL)
defer func() {
if r := recover(); r != nil {
log.Error(r)
buf := make([]byte, 4096)
n := runtime.Stack(buf, false)
fmt.Fprintln(os.Stderr, string(buf[:n]))
}
}()
if !allowOrigin(r, i.cfg) || !allowReferer(r, i.cfg) {
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("403 - Forbidden"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment