Respond with error in case of panic

This commit is contained in:
Samuel Lorch 2023-04-07 21:54:29 +02:00
parent db4b108ba8
commit b71525ba30

View file

@ -82,6 +82,7 @@ func (h *Handler) HandleRequest(ctx context.Context, s *session.Session, r io.Re
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
slog.Error("Recovered Panic Executing API Method", fmt.Errorf("%v", r), "method", req.Method, "params", fmt.Sprintf("%+v", params[2]), "id", req.ID, "stack", debug.Stack()) slog.Error("Recovered Panic Executing API Method", fmt.Errorf("%v", r), "method", req.Method, "params", fmt.Sprintf("%+v", params[2]), "id", req.ID, "stack", debug.Stack())
respondError(w, req.ID, ErrInternalError, fmt.Errorf("%v", r))
} }
}() }()
res := method.handlerFunc.Call(params) res := method.handlerFunc.Call(params)