Bug: scope error in server/index.js duplicate email handler #50

Closed
opened 2026-05-17 17:20:51 -05:00 by null · 0 comments
Owner

Issue

In server/index.js at lines 425-427, the code in the duplicate email error handler references sanitized.email and calls forwardToZoho(sanitized), but the sanitized variable is not in scope within the catch block.

Location

  • File: server/index.js
  • Lines: 425-427 (catch block)

Expected Behavior

When a duplicate email is submitted, the 409 Conflict response should be returned with a warning logged, and Zoho forwarding should still be attempted.

Actual Behavior

The code will fail with a ReferenceError because sanitized is not defined in the catch block scope, likely causing a 500 error instead of the proper 409 response.

Fix

Move the sanitized variable declaration before the try block so it's accessible in both the try and catch blocks:

// Move sanitized declaration before try block
const sanitized = sanitizePayload(parsed.data, {
  company: 200,
  name: 100,
  email: 254,
  phone: 50,
  zip: 10,
  message: 5000,
  service_interest: 50,
});

try {
  // ... rest of the try block
} catch (err) {
  // Now sanitized is accessible here
  if (errorMsg.includes('unique constraint') || errorMsg.includes('duplicate')) {
    log.warn(`Duplicate lead email: ${sanitized.email}`);
    forwardToZoho(sanitized);
    // ...
  }
}
## Issue In `server/index.js` at lines 425-427, the code in the duplicate email error handler references `sanitized.email` and calls `forwardToZoho(sanitized)`, but the `sanitized` variable is not in scope within the `catch` block. ## Location - File: `server/index.js` - Lines: 425-427 (catch block) ## Expected Behavior When a duplicate email is submitted, the 409 Conflict response should be returned with a warning logged, and Zoho forwarding should still be attempted. ## Actual Behavior The code will fail with a ReferenceError because `sanitized` is not defined in the catch block scope, likely causing a 500 error instead of the proper 409 response. ## Fix Move the `sanitized` variable declaration before the `try` block so it's accessible in both the `try` and `catch` blocks: ```js // Move sanitized declaration before try block const sanitized = sanitizePayload(parsed.data, { company: 200, name: 100, email: 254, phone: 50, zip: 10, message: 5000, service_interest: 50, }); try { // ... rest of the try block } catch (err) { // Now sanitized is accessible here if (errorMsg.includes('unique constraint') || errorMsg.includes('duplicate')) { log.warn(`Duplicate lead email: ${sanitized.email}`); forwardToZoho(sanitized); // ... } } ```
null added the
bug
backend
labels 2026-05-17 17:20:51 -05:00
null closed this issue 2026-05-17 18:04:27 -05:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: null/Queue-North-Website#50
No description provided.