Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(session): describe the pairing-code 409 in terms of qr_ready

Yudhi Armyndharisaf24de0035cc
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index ef593682c..95fda6178 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -718,7 +718,7 @@ Request an 8-char pairing code to link via phone number (alternative to QR).
`status` is the lowercase session status.
-**Errors:** `400` validation, or session not started, or already authenticated · `401` · `403` · `404` not found · `409` conflict or engine not ready (retryable)
+**Errors:** `400` validation, or session not started, or already authenticated · `401` · `403` · `404` not found · `409` session not waiting to be linked yet; wait for `status` to read `qr_ready` and retry
#### POST /api/sessions/:sessionId/presence/subscribe
diff --git a/openapi.json b/openapi.json
index a22c05b06..6cf590b13 100644
--- a/openapi.json
+++ b/openapi.json
@@ -821,7 +821,7 @@
"description": "Session not found"
},
"409": {
- "description": "The session is not connected — an engine exists for it but is not `ready`: disconnected, reconnecting, or still initializing, so the request never reached WhatsApp. Wait for `ready` and retry. A session that was never started answers `400` instead, and the session lifecycle routes answer `409` for a conflicting state rather than this. One window answers this while the session still reads `ready`: WhatsApp Web periodically reloads its own page and the engine re-injects into it — for those few seconds the answer is a `409` naming the reload; retry shortly."
+ "description": "The session is not waiting to be linked: the engine is still connecting, or reconnecting after a drop, so the request never reached WhatsApp. Wait for `status` to read `qr_ready` and retry. A session that reads `ready` is already linked and answers `400` instead."
}
},
"summary": "Request an 8-char pairing code to link via phone number (alternative to QR)",
diff --git a/src/common/openapi/engine-status-responses.ts b/src/common/openapi/engine-status-responses.ts
index 4e930344f..785135bc1 100644
--- a/src/common/openapi/engine-status-responses.ts
+++ b/src/common/openapi/engine-status-responses.ts
@@ -22,6 +22,16 @@ export const ENGINE_NOT_READY_409 =
'still reads `ready`: WhatsApp Web periodically reloads its own page and the engine re-injects ' +
'into it — for those few seconds the answer is a `409` naming the reload; retry shortly.';
+/**
+ * `EngineNotReadyError` (409) on `POST /sessions/:sessionId/pairing-code`, where the generic wording
+ * above points the caller at the wrong state: both engines accept a pairing request only while the
+ * session is `qr_ready`, and a session that reads `ready` is already linked and answers `400`.
+ */
+export const PAIRING_NOT_READY_409 =
+ 'The session is not waiting to be linked: the engine is still connecting, or reconnecting after a ' +
+ 'drop, so the request never reached WhatsApp. Wait for `status` to read `qr_ready` and retry. A ' +
+ 'session that reads `ready` is already linked and answers `400` instead.';
+
/**
* The catalog and status services pass a `NotFoundException` factory to `EngineRegistry.require()`
* instead of taking its `BadRequestException` default, so on those routes an unstarted session is a
diff --git a/src/modules/session/session.controller.ts b/src/modules/session/session.controller.ts
index 7f5b9aab0..e355891e8 100644
--- a/src/modules/session/session.controller.ts
+++ b/src/modules/session/session.controller.ts
@@ -43,7 +43,7 @@ import { AuditService } from '../audit/audit.service';
import { AuditAction } from '../audit/entities/audit-log.entity';
import { RequireRole, CurrentApiKey, SessionScoped, RequireUnscopedKey } from '../auth/decorators/auth.decorators';
import { ApiKey, ApiKeyRole } from '../auth/entities/api-key.entity';
-import { ENGINE_NOT_READY_409 } from '../../common/openapi/engine-status-responses';
+import { ENGINE_NOT_READY_409, PAIRING_NOT_READY_409 } from '../../common/openapi/engine-status-responses';
@ApiTags('sessions')
@Controller('sessions')
@@ -376,7 +376,7 @@ export class SessionController {
@ApiResponse({ status: 201, description: 'Pairing code generated', type: PairingCodeResponseDto })
@ApiResponse({ status: 400, description: 'Session not started or already authenticated' })
@ApiResponse({ status: 404, description: 'Session not found' })
- @ApiResponse({ status: 409, description: ENGINE_NOT_READY_409 })
+ @ApiResponse({ status: 409, description: PAIRING_NOT_READY_409 })
async requestPairingCode(
@Param('sessionId', ParseUUIDPipe) id: string,
@Body() dto: RequestPairingCodeDto,