Skip to content

[Bug] POST /api/streak/freeze always returns 201 even when freeze already existed #1475

Closed

Description

@Midoriya-w

This issue is raised as part of GSSoC'26. Kindly consider assigning it to me.

Summary

In src/app/api/streak/freeze/route.ts, the POST handler always
returns HTTP 201 Created regardless of whether the freeze was newly
created or already existed:

return Response.json(
{ freeze, already_existed: alreadyExisted },
{ status: 201 }
);

The already_existed flag is correctly computed but the HTTP status
code is wrong for the already-existed case. Returning 201 when a
resource already exists violates REST semantics — 201 means a new
resource was created, while 200 means the request succeeded on an
existing resource.

Steps to Reproduce

  1. Call POST /api/streak/freeze for a user
  2. Call POST /api/streak/freeze again for the same user on the same day
  3. Observe both responses return 201 — second should return 200

Expected Behavior

  • First freeze creation → 201 Created
  • Freeze already existed → 200 OK with already_existed: true

Actual Behavior

Both cases return 201 regardless of whether the freeze was new
or pre-existing.

Fix

const statusCode = alreadyExisted ? 200 : 201;
return Response.json(
{ freeze, already_existed: alreadyExisted },
{ status: statusCode }
);

Activity

  1. added
    bug
    needs-triage
    on May 29, 2026
  2. Midoriya-w commented on May 29, 2026

    @Midoriya-w
    ContributorAuthor

    Hey @Priyanshu-byte-coder I discovered this bug while auditing the codebase and would love to fix it under GSSoC 2026. Can I get assigned?

  3. github-actions commented on May 29, 2026

    @github-actions

    Thanks for opening your first issue on DevTrack! 🎉

    A maintainer will take a look shortly. In the meantime:

    If you find DevTrack useful, a ⭐ star on the repo is always appreciated — it helps the project reach more developers!

  4. Midoriya-w commented on May 29, 2026

    @Midoriya-w
    ContributorAuthor

    Hey @Priyanshu-byte-coder,

    Just submitted a fix for this issue. The response now returns 201 for a newly created freeze and 200 when the freeze already exists.

    PR: #1542

    Looking forward to your feedback.

  5. github-actions commented on May 30, 2026

    @github-actions

    ✅ Closed as completed!

    If DevTrack has been useful, a ⭐ star on the repo helps the project grow and reach more developers.

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

Metadata

Metadata

Assignees

Labels

bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions