fix: global handler recoverer
This commit is contained in:
parent
468a09be8d
commit
11aa9f0a0f
|
@ -1,6 +1,7 @@
|
||||||
package aicra
|
package aicra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/api"
|
"git.xdrm.io/go/aicra/api"
|
||||||
|
@ -13,6 +14,13 @@ type Handler Builder
|
||||||
|
|
||||||
// ServeHTTP implements http.Handler
|
// ServeHTTP implements http.Handler
|
||||||
func (s Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
defer func() {
|
||||||
|
if rc := recover(); rc != nil {
|
||||||
|
log.Printf("recovering request: %s\n", rc)
|
||||||
|
// try to send error response
|
||||||
|
api.EmptyResponse().WithError(api.ErrUncallableService).ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
|
|
||||||
// 1. find a matching service from config
|
// 1. find a matching service from config
|
||||||
|
|
Loading…
Reference in New Issue