Skip to content

Commit

Permalink
Invalid stats report request causes 500 return code
Browse files Browse the repository at this point in the history
Fixes #3229
  • Loading branch information
maartenba committed Sep 13, 2016
1 parent 1589c73 commit 193cc4c
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/NuGetGallery/Controllers/StatisticsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ public partial class StatisticsController
private readonly IStatisticsService _statisticsService = null;
private readonly IAggregateStatsService _aggregateStatsService = null;

private static readonly string[] PackageDownloadsByVersionDimensions = new[] {
Constants.StatisticsDimensions.Version,
Constants.StatisticsDimensions.ClientName,
Constants.StatisticsDimensions.ClientVersion,
Constants.StatisticsDimensions.Operation
};

private static readonly string[] PackageDownloadsDetailDimensions = new [] {
Constants.StatisticsDimensions.ClientName,
Constants.StatisticsDimensions.ClientVersion,
Constants.StatisticsDimensions.Operation
};

public StatisticsController(IAggregateStatsService aggregateStatsService)
{
_statisticsService = null;
Expand Down Expand Up @@ -148,16 +161,17 @@ public virtual async Task<ActionResult> PackageDownloadsByVersion(string id, str
return new HttpStatusCodeResult(HttpStatusCode.NotFound);
}

var dimensions = new []
StatisticsPackagesReport report = null;
try
{
Constants.StatisticsDimensions.Version,
Constants.StatisticsDimensions.ClientName,
Constants.StatisticsDimensions.ClientVersion,
Constants.StatisticsDimensions.Operation
};
report = await _statisticsService.GetPackageDownloadsByVersion(id);

StatisticsPackagesReport report = await _statisticsService.GetPackageDownloadsByVersion(id);
ProcessReport(report, groupby, dimensions, id);
ProcessReport(report, groupby, PackageDownloadsByVersionDimensions, id);
}
catch (StatisticsReportNotFoundException)
{
// no report found
}

if (report != null)
{
Expand All @@ -183,14 +197,17 @@ public virtual async Task<ActionResult> PackageDownloadsDetail(string id, string
return new HttpStatusCodeResult(HttpStatusCode.NotFound);
}

var dimensions = new[] {
Constants.StatisticsDimensions.ClientName,
Constants.StatisticsDimensions.ClientVersion,
Constants.StatisticsDimensions.Operation };

StatisticsPackagesReport report = await _statisticsService.GetPackageVersionDownloadsByClient(id, version);
StatisticsPackagesReport report = null;
try
{
report = await _statisticsService.GetPackageVersionDownloadsByClient(id, version);

ProcessReport(report, groupby, dimensions, null);
ProcessReport(report, groupby, PackageDownloadsDetailDimensions, null);
}
catch (StatisticsReportNotFoundException)
{
// no report found
}

if (report != null)
{
Expand Down

0 comments on commit 193cc4c

Please sign in to comment.