Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(engine): keep a WhatsApp 408 on channel create out of 503

Yudhi Armyndharis487f4a6f7429
diff --git a/src/engine/adapters/baileys-channels.ts b/src/engine/adapters/baileys-channels.ts
index 78f34df0c..8e6899548 100644
--- a/src/engine/adapters/baileys-channels.ts
+++ b/src/engine/adapters/baileys-channels.ts
@@ -129,13 +129,18 @@ export class BaileysChannels {
* Deliberately NOT bounded, unlike every other call here: creating a channel is non-idempotent,
* and 503 is a backpressure status the Go SDK retries three times for POST (sdk/go/retry.go).
* A deadline abandons without cancelling, so a slow-but-succeeding create could leave duplicates.
+ * An unanswered query therefore still surfaces opaquely rather than as something retryable, and so
+ * does WA code 408: a server timeout does not say whether the channel was created.
*/
async createChannel(name: string, description?: string): Promise<Channel> {
this.host.ensureReady();
const meta = await mapServerRefusal(
'Creating the channel',
() => this.sock().newsletterCreate(name, description),
- wmexRefusalCode,
+ error => {
+ const code = wmexRefusalCode(error);
+ return code === 408 ? undefined : code;
+ },
);
return this.toChannel(meta);
}
diff --git a/src/engine/adapters/baileys-wmex-refusal.spec.ts b/src/engine/adapters/baileys-wmex-refusal.spec.ts
index 767c2ad98..fe49332ea 100644
--- a/src/engine/adapters/baileys-wmex-refusal.spec.ts
+++ b/src/engine/adapters/baileys-wmex-refusal.spec.ts
@@ -121,6 +121,15 @@ describe('what must NOT be classified as a refusal', () => {
);
});
+ it('a WhatsApp 408 on channel create stays opaque rather than becoming a retryable 503', async () => {
+ // A server timeout does not say whether the channel was created, and a 503 invites a retried POST.
+ const timedOut = wmexRefusal(408);
+ const newsletterCreate = jest.fn().mockRejectedValue(timedOut);
+ const result = channels({ newsletterCreate }, 500).createChannel('N');
+ await expect(result).rejects.toBe(timedOut);
+ await expect(result).rejects.not.toBeInstanceOf(EngineTransportError);
+ });
+
it('the WMex no-answer shape is not a refusal either — its data is null', async () => {
// executeWMexQuery's other throw: Boom(..., { statusCode: 400, data: result }) with result
// undefined, which Boom normalises to null.