#3071: fix: WhatsApp 515 error retry not triggering
channel: whatsapp-web
Cluster:
WhatsApp Connection Stability Fixes
## 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
#9515: fix(web): retry WhatsApp 515 restart up to 3 times with delay
by Sebachowa · 2026-02-05
85.5%
#9727: fix(whatsapp): retry reconnect loop on initial connection failure
by luizlf · 2026-02-05
78.7%
#16923: fix(web): resolve stale socket race condition in WhatsApp auto-reply
by dorukardahan · 2026-02-15
77.5%
#17487: fix: WhatsApp connection stability - continue reconnection after ma...
by MisterGuy420 · 2026-02-15
76.1%
#19303: Fix WhatsApp internal error leakage + cron.run timeout defaults
by koala73 · 2026-02-17
75.3%
#15650: fix(whatsapp): pass fileName to document sends instead of hardcodin...
by whoknowsmann · 2026-02-13
73.8%
#16817: fix(whatsapp): infer extension-aware fallback filename for Baileys ...
by VintLin · 2026-02-15
73.7%
#14789: fix: per-account dmPolicy ignored in checkInboundAccessControl
by croll83 · 2026-02-12
73.7%
#9606: fix: pass fileName to WhatsApp document messages
by AytuncYildizli · 2026-02-05
73.7%
#11249: fix(whatsapp): prevent pairing-mode auto-replies to unknown DMs
by liuxiaopai-ai · 2026-02-07
73.6%