Skip to content

Move origin extraction outside try block in email subscription handlers #67623

Closed

Description

@Nithin0620

Description

In both the /ue/:unsubscribeId and /resubscribe/:unsubscribeId handlers, origin is currently declared inside the try block:

try {
  const { origin } = getRedirectParams(req);
  // ...
} catch (error) {
  return reply.redirectWithMessage(origin, { ... }); // ❌ ReferenceError
}

Because const is block-scoped, origin is not accessible inside the catch block. If an unexpected error occurs before the redirect (for example, a Prisma connection failure), the catch block itself throws:

ReferenceError: origin is not defined

This results in a 500 response instead of a graceful redirect with an error message.

Fix

Move:

const { origin } = getRedirectParams(req);

outside the try block so origin is available throughout the entire handler, including the catch block.

Affected File

  • api/src/routes/public/email-subscription.ts

Activity

  1. added
    platform: api
    status: waiting triage
    on May 28, 2026
  2. added
    help wanted
    and removed
    status: waiting triage
    on May 28, 2026
  3. added a commit that references this issue on May 28, 2026
    4d02129
  4. MannXo commented on May 28, 2026

    @MannXo

    Interested in working on this. Can I be assigned?

  5. Jeevankumar-s commented on May 28, 2026

    @Jeevankumar-s
    Member

    Interested in working on this. Can I be assigned?

    We typically do not assign issues. Instead, we accept the first pull request that comprehensively solves the issue.

    Issues labeled with help wanted or first timers only are open for contributions.

    Please make sure you read our guidelines for contributing. We prioritize contributors following the instructions in our guide. Join us in our chat room or the forum if you need help contributing - our community will be happy to assist you.

  6. added
    status: PR in works
    and removed
    help wanted
    on Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform: apistatus: PR in works

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions