Skip to content

Commit b36ee73

Browse files
fix: add comprehensive error logging to dashboard API endpoints
Add structured logging for database errors in scan details and findings endpoints to improve debugging of 500 errors. Logs include: - Scan not found (404) warnings with scan ID - Database query errors with context - Scan events fetch failures This helps diagnose issues when dashboard shows "Failed to fetch scan" errors by providing detailed error logs with scan IDs and error details. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d8d3e9d commit b36ee73

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

internal/api/dashboard.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,19 @@ func RegisterDashboardRoutes(router *gin.Engine, db *sqlx.DB, log *logger.Logger
9090
`, scanID).Scan(&scan.ID, &scan.Target, &scan.Type, &scan.Status, &scan.CreatedAt, &scan.StartedAt, &scan.CompletedAt, &scan.ErrorMsg, &scan.Config, &scan.Result, &scan.Checkpoint)
9191

9292
if err == sql.ErrNoRows {
93+
log.Warnw("Scan not found in database",
94+
"scan_id", scanID,
95+
"component", "dashboard_api",
96+
)
9397
c.JSON(http.StatusNotFound, gin.H{"error": "Scan not found"})
9498
return
9599
}
96100
if err != nil {
101+
log.Errorw("Database error fetching scan details",
102+
"error", err,
103+
"scan_id", scanID,
104+
"component", "dashboard_api",
105+
)
97106
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
98107
return
99108
}
@@ -104,6 +113,11 @@ func RegisterDashboardRoutes(router *gin.Engine, db *sqlx.DB, log *logger.Logger
104113
FROM findings WHERE scan_id = $1 ORDER BY severity DESC, created_at DESC
105114
`, scanID)
106115
if err != nil {
116+
log.Errorw("Database error fetching findings",
117+
"error", err,
118+
"scan_id", scanID,
119+
"component", "dashboard_api",
120+
)
107121
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
108122
return
109123
}
@@ -153,6 +167,11 @@ func RegisterDashboardRoutes(router *gin.Engine, db *sqlx.DB, log *logger.Logger
153167
LIMIT 1000
154168
`, scanID)
155169
if err != nil {
170+
log.Warnw("Failed to fetch scan events, returning empty list",
171+
"error", err,
172+
"scan_id", scanID,
173+
"component", "dashboard_api",
174+
)
156175
c.JSON(http.StatusOK, []interface{}{}) // Return empty if no events table
157176
return
158177
}

0 commit comments

Comments
 (0)