fix(response): add nil check for c.Request in error logging

Prevents panic when ErrorFrom is called in test contexts where
gin.CreateTestContext doesn't set up an HTTP request.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Gemini Wen
2026-01-27 19:26:44 +08:00
parent fc17d9d7df
commit 8f6639f825

View File

@@ -77,7 +77,7 @@ func ErrorFrom(c *gin.Context, err error) bool {
statusCode, status := infraerrors.ToHTTP(err)
// Log internal errors with full details for debugging
if statusCode >= 500 {
if statusCode >= 500 && c.Request != nil {
log.Printf("[ERROR] %s %s\n Error: %s", c.Request.Method, c.Request.URL.Path, err.Error())
}