fix(api): answer 200 when analytics hold no record for a package

Analytics live in memory and restart empty. A package with no record yet
returned 404, which every browser logs as a failed request on the
Downloads tab. The endpoint now returns a null package.
This commit is contained in:
2026-11-24 02:05:55 +00:00
parent 7470c41560
commit bc56b97677
2 changed files with 7 additions and 9 deletions
+3 -7
View File
@@ -97,13 +97,9 @@ func (a *App) handleAnalyticsPackageStats(c fiber.Ctx) error {
})
}
stats, exists := a.analyticsEngine.GetPackageStats(registry, name)
if !exists {
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
"error": "package not found in analytics",
})
}
// Analytics live in memory and restart empty, so a package with no record yet is a normal
// answer, not a missing resource: a 404 here shows up as a failed request in every client.
stats, _ := a.analyticsEngine.GetPackageStats(registry, name)
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"package": stats,
})