Wei-Shaw/sub2api · error

failed to get dashboard statistics

Error message

failed to get dashboard statistics

What it means

Returned while assembling the v2 dashboard snapshot when includeStats is true and the underlying dashboardService.GetDashboardStats call fails. The original error is discarded and replaced with this generic message, so the real cause (usually a database failure) is only visible in server logs. It is a transient/infrastructure error, not a request-format problem.

Source

Thrown at backend/internal/handler/admin/dashboard_snapshot_v2_handler.go:168

func (h *DashboardHandler) buildSnapshotV2Response(
	ctx context.Context,
	startTime, endTime time.Time,
	granularity string,
	filters *dashboardSnapshotV2Filters,
	includeStats, includeTrend, includeModels, includeGroups, includeUsersTrend bool,
	usersTrendLimit int,
) (*dashboardSnapshotV2Response, error) {
	resp := &dashboardSnapshotV2Response{
		GeneratedAt: time.Now().UTC().Format(time.RFC3339),
		StartDate:   startTime.Format("2006-01-02"),
		EndDate:     endTime.Add(-24 * time.Hour).Format("2006-01-02"),
		Granularity: granularity,
	}

	if includeStats {
		stats, err := h.dashboardService.GetDashboardStats(ctx)
		if err != nil {
			return nil, errors.New("failed to get dashboard statistics")
		}
		resp.Stats = &dashboardSnapshotV2Stats{
			DashboardStats: *stats,
			Uptime:         int64(time.Since(h.startTime).Seconds()),
		}
	}

	if includeTrend {
		trend, _, err := h.getUsageTrendCached(
			ctx,
			startTime,
			endTime,
			granularity,
			filters.UserID,
			filters.APIKeyID,
			filters.AccountID,
			filters.GroupID,
			filters.Model,

View on GitHub (pinned to 073e92d171)

Solutions

  1. Retry the snapshot request after a short delay — most causes are transient DB issues
  2. Check backend logs for the underlying GetDashboardStats error at that timestamp
  3. Verify database connectivity, pool limits, and that usage stats tables exist and are migrated
  4. As a workaround, request the snapshot without stats (exclude the stats section) to get trend/model data
Defensive patterns

Strategy: retry

Try / catch

// TS: retry with backoff, degrade gracefully
try { snapshot = await getSnapshotV2({ includeStats: true }); }
catch (e) {
  if (e.message === 'failed to get dashboard statistics') {
    snapshot = await retry(async () => getSnapshotV2({ includeStats: false }), { tries: 3 });
  } else throw e;
}

Prevention

When it happens

Trigger: GET /admin dashboard snapshot v2 endpoint with stats included (include_stats / default true) while the usage-stats database is unreachable, timing out, or has a schema/lock problem.

Common situations: Database connection pool exhaustion under load; migrations leaving stats tables missing; long-running aggregate queries hitting statement timeouts after data growth.

Related errors


AI-assisted analysis of Wei-Shaw/sub2api@073e92d171 (2026-08-15). Data as JSON: /api/errors/78ecb5d82efb2164. Report an issue: GitHub.