improved error page handling by tapping into Echo and its middleware

This commit is contained in:
2025-10-19 16:06:08 -06:00
parent e77ecf2a06
commit 13644f4ecb
5 changed files with 65 additions and 8 deletions
+14 -1
View File
@@ -11,7 +11,10 @@
package main
import (
"bufio"
"bytes"
"io"
"strings"
"time"
"github.com/labstack/echo/v4"
@@ -119,8 +122,18 @@ func LogrusMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
"uri": req.RequestURI,
"status": res.Status,
"latency_ms": stop.Sub(start).Milliseconds(),
"user_agent": req.UserAgent(),
}).Info("handled request")
return err
}
}
// LogrusPanicLogging is a log function hooked into the recovery middleware.
func LogrusPanicLogging(c echo.Context, err error, stack []byte) error {
log.Errorf("[PANIC RECOVERY] %v", err)
scanner := bufio.NewScanner(bytes.NewReader(stack))
for scanner.Scan() {
line := strings.ReplaceAll(scanner.Text(), "\t", " ")
log.Error(line)
}
return scanner.Err()
}