From 818560df173589d20721fd471b735a6cc94d0858 Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Sat, 19 Nov 2022 19:23:39 +0100 Subject: [PATCH] optimized the inerrupt handling --- middleware/middleware.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/middleware/middleware.go b/middleware/middleware.go index cdd75be..38cef43 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -23,10 +23,14 @@ func LogMiddleware(c *gin.Context) { var entry *zerolog.Event interrupt := recover() if interrupt != nil { - err := interrupt.(error) + entry = log.Error().Int("statuscode", 500) + if err, ok := interrupt.(error); ok { + entry.Err(err).Stack() + } else { + entry.Interface("recover", interrupt) + } c.Header("requestid", id.String()) c.AbortWithStatus(http.StatusInternalServerError) - entry = log.Error().Err(err).Int("statuscode", 500) entry.Stack() } else { statuscode := c.Writer.Status()