Add nice(r) error message on api server panic. Fix nil ptr derefs.

This commit is contained in:
Daniel Smith
2014-06-13 14:58:08 -07:00
parent 9cd9754693
commit b95eef522b
3 changed files with 16 additions and 0 deletions

View File

@@ -70,6 +70,13 @@ func (server *ApiServer) handleIndex(w http.ResponseWriter) {
// HTTP Handler interface
func (server *ApiServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
defer func() {
if x := recover(); x != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, "apiserver panic. Look in log for details.")
log.Printf("ApiServer panic'd: %#v\n", x)
}
}()
log.Printf("%s %s", req.Method, req.RequestURI)
url, err := url.ParseRequestURI(req.RequestURI)
if err != nil {