Skip to content

fix(analytics): validate range parameter and return 400 for unsupport… - #869

Open
jikrana1 wants to merge 1 commit into
Userunknown84:mainfrom
jikrana1:fix/validate-analytics-range-858
Open

fix(analytics): validate range parameter and return 400 for unsupport…#869
jikrana1 wants to merge 1 commit into
Userunknown84:mainfrom
jikrana1:fix/validate-analytics-range-858

Conversation

@jikrana1

Copy link
Copy Markdown
Contributor

Closes #858

Problem description

The getTrends endpoint currently falls back to the default daily range whenever an unsupported range value is provided (e.g., ?range=yearly). This silent fallback hides client-side mistakes and makes debugging more difficult because invalid requests still return successful responses.

Proposed solution

Added explicit validation for the range query parameter.

Implementation details:

  • Check if range is present and not in ANALYTICS_RANGES (daily, weekly, monthly).
  • If invalid, return a 400 Bad Request with a clear error message listing the supported values.
  • If range is not provided, keep the existing default behavior (daily).
  • Preserves all existing functionality for valid requests.

Benefits

  • ✅ Improves API validation.
  • ✅ Makes debugging easier for client developers.
  • ✅ Prevents unintended analytics results due to typos.

Testing instructions

  1. Call /analytics/trends?range=yearly. Should return a 400 Bad Request error.
  2. Call /analytics/trends?range=daily. Should return the daily trends normally.
  3. Call /analytics/trends without any range. Should still default to daily and return data.

@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Userunknown84 Userunknown84 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge Conflict shown.

@Userunknown84 Userunknown84 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge conflict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate Analytics Range Parameter and Return 400 for Unsupported Values

2 participants