Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(message): log a send that fails inside the engine

Yudhi Armyndharisafb94e0115fc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 52d2c3eb9..fac0751fd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -77,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The dashboard disables a session's Start and Reconnect buttons while its start request is in flight.
- whatsapp-web.js sessions no longer report a call rejection that did not stop the call: the call reject route answers `501` and `autoRejectCalls` logs a failed auto-reject.
- A Baileys session added to or joining a group emits `group.join`, as whatsapp-web.js already did.
+- A send that fails inside the engine logs a warning carrying the session, chat, message id and the engine's error, where only Nest's generic `[ExceptionsHandler]` line recorded it before ([#1679](https://github.com/rmyndharis/OpenWA/issues/1679)). Thanks @DavidgFernandes for the report.
### Documentation
diff --git a/src/modules/message/message-send.service.spec.ts b/src/modules/message/message-send.service.spec.ts
index 2eb33e03f..1bbb2696e 100644
--- a/src/modules/message/message-send.service.spec.ts
+++ b/src/modules/message/message-send.service.spec.ts
@@ -299,6 +299,35 @@ describe('MessageSendService', () => {
expect(calls[1][1]).toMatchObject({ message: { status: MessageStatus.FAILED } });
});
+ it('logs an engine-side send failure with the session, chat and type', async () => {
+ const warn = jest.spyOn(
+ (service as unknown as { logger: { warn: (...args: unknown[]) => void } }).logger,
+ 'warn',
+ );
+ const pageError = new Error('t');
+ pageError.name = 't';
+ mockEngine.sendTextMessage.mockRejectedValueOnce(pageError);
+
+ await expect(service.sendText('sess-1', { chatId: '[email protected]', text: 'hi' })).rejects.toThrow();
+
+ expect(warn).toHaveBeenCalledWith(
+ 'Send failed in the engine (text)',
+ expect.objectContaining({ sessionId: 'sess-1', chatId: '[email protected]', error: 't: t' }),
+ );
+ });
+
+ it('does not log a client-fault send failure', async () => {
+ const warn = jest.spyOn(
+ (service as unknown as { logger: { warn: (...args: unknown[]) => void } }).logger,
+ 'warn',
+ );
+ mockEngine.sendTextMessage.mockRejectedValueOnce(new BadRequestException('bad chat id'));
+
+ await expect(service.sendText('sess-1', { chatId: '[email protected]', text: 'hi' })).rejects.toThrow();
+
+ expect(warn).not.toHaveBeenCalledWith('Send failed in the engine (text)', expect.anything());
+ });
+
it('reconciles provider indexes when the send echo won the race: upsert the surviving row + drop the ghost (#906)', async () => {
const echoRow = {
id: 'echo-uuid-9',
diff --git a/src/modules/message/message-send.service.ts b/src/modules/message/message-send.service.ts
index a4a664c89..3cd8dea32 100644
--- a/src/modules/message/message-send.service.ts
+++ b/src/modules/message/message-send.service.ts
@@ -186,6 +186,15 @@ export class MessageSendService {
// requests trip the breaker on a healthy session.
if (countsTowardSendBreaker(error)) {
this.pacing.recordSendFailure(sessionId);
+ // The same classification picks the failures worth a log line. Otherwise an engine-side failure
+ // leaves only Nest's generic `[ExceptionsHandler]` line, with no session, chat or message type to
+ // correlate it with; a minified page error reads as `t: t` there.
+ this.logger.warn(`Send failed in the engine (${type})`, {
+ sessionId,
+ chatId: message.chatId,
+ messageId: message.id,
+ error: error instanceof Error ? `${error.name}: ${error.message}` : String(error),
+ });
}
await this.saveFailedMessage(message);
// Sanitize the hook payload: an SSRF block's raw .message names the resolved internal address