Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): report a Baileys picture lookup server error as 503
Yudhi Armyndharisc5dfb70195cb
diff --git a/src/engine/adapters/baileys-contacts.ts b/src/engine/adapters/baileys-contacts.tsindex c9545cdc1..17513fe3c 100644--- a/src/engine/adapters/baileys-contacts.ts+++ b/src/engine/adapters/baileys-contacts.ts@@ -98,9 +98,9 @@ export class BaileysContacts {if (code === undefined) {throw new EngineTransportError('WhatsApp did not answer the profile picture lookup');}- // A rate limit or server timeout (408/429) is not a verdict about the picture either.- if (code === 408 || code === 429) {- throw new EngineTransportError(`WhatsApp rate-limited or timed out the profile picture lookup (code ${code})`);+ // A rate limit, server timeout (408/429) or server error (5xx) is not a verdict about the picture either.+ if (code === 408 || code === 429 || code >= 500) {+ throw new EngineTransportError(`WhatsApp could not answer the profile picture lookup (code ${code})`);}this.host.logger.debug('profilePictureUrl failed; no picture or hidden', {contactId,diff --git a/src/engine/adapters/baileys-profile-picture.spec.ts b/src/engine/adapters/baileys-profile-picture.spec.tsindex 4c715897c..5d80c9272 100644--- a/src/engine/adapters/baileys-profile-picture.spec.ts+++ b/src/engine/adapters/baileys-profile-picture.spec.ts@@ -49,6 +49,16 @@ describe('getProfilePicture', () => {);});+ it.each([+ ['internal-server-error', 500],+ ['service-unavailable', 503],+ ])('reports a WhatsApp server error (%s) instead of "no picture"', async (text, code) => {+ const profilePictureUrl = jest.fn().mockRejectedValue(new Boom(text, { data: code }));+ await expect(contacts({ profilePictureUrl }, 500).getProfilePicture('[email protected]')).rejects.toBeInstanceOf(+ EngineTransportError,+ );+ });+it('reports a connection that closed mid-lookup instead of "no picture"', async () => {const profilePictureUrl = jest.fn().mockRejectedValue(new Boom('Connection Closed', { statusCode: 428 }));await expect(contacts({ profilePictureUrl }, 500).getProfilePicture('[email protected]')).rejects.toBeInstanceOf(