← Back to PRs

#3071: fix: WhatsApp 515 error retry not triggering

by rabsef-bicrym open 2026-01-28 01:50 View on GitHub →
channel: whatsapp-web
## Problem The WhatsApp QR login auto-retry feature for 515 errors (added in 3b63d1cb) has never worked in production. When WhatsApp returns a 515 "restart required" error after QR pairing, the automatic reconnection logic fails to trigger, causing immediate login failures. ## Root Cause Baileys wraps disconnect errors in nested structures like: ``` { lastDisconnect: { error: { output: { statusCode: 515 } } } } ``` However, `getStatusCode()` only checked shallow locations (`err.output.statusCode` and `err.status`), so it returned `undefined` instead of `515`. This caused the retry check (`login.errorStatus === 515`) to never match. Meanwhile, `formatError()` correctly used `extractBoomDetails()` to check nested error locations, which is why error messages displayed "status=515" even though `login.errorStatus` was `undefined`. ## Solution Update `getStatusCode()` to use the same `extractBoomDetails()` logic as `formatError()`, ensuring it checks: - `err.error` - `err.lastDisconnect.error` for nested Boom-style status codes. ## Testing Existing test passes. Verified in production that 515 retry now triggers correctly and WhatsApp login succeeds after automatic reconnection. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR fixes WhatsApp Web QR login auto-retry on Baileys “515 restart required” disconnects by teaching `getStatusCode()` to extract Boom-style status codes from the same nested error locations that `formatError()` already handles (`err`, `err.error`, and `err.lastDisconnect.error`). This aligns the retry logic (which depends on a numeric status code) with the error formatting logic, so production reconnect triggers for 515 instead of failing immediately. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk; it’s a narrow, behavior-correcting change to status code extraction. - The change is localized to `getStatusCode()` and reuses the existing `extractBoomDetails()` logic already relied on by `formatError()`, reducing the chance of unintended behavior differences while fixing a clear mismatch (nested Baileys errors). No new side effects or external dependencies were introduced. - src/web/session.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs