Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(status): log a status post the engine refused with its session

Yudhi Armyndharisbc30d8921a6e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 60921acfa..379fce3ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The JavaScript SDK smoke check sends requests through both built clients, so the Node 18 CI lane covers the request path.
- Retire the whatsapp-web.js download-mimetype install patch; inbound media downloads now pass the mimetype themselves.
- A whatsapp-web.js inbound media download the page answers with nothing logs a warning, and one WhatsApp Web rejects is logged with the rejection's name, message and WhatsApp Web build instead of the minified `t: t`.
+- A status post the engine refuses is logged with its session and type, as a failed chat send already is.
- Storage import abort messages name the `STORAGE_IMPORT_MAX_BYTES` or `STORAGE_IMPORT_MAX_ENTRIES` setting that stopped them.
- CI and the weekly security scan run `npm audit` over the JavaScript SDK, and Dependabot watches its lockfile.
- The Baileys linked-device name defaults to `Ubuntu` instead of `OpenWA`, so phone-number pairing works without setting `BAILEYS_BROWSER_NAME`.
diff --git a/src/modules/status/status.service.spec.ts b/src/modules/status/status.service.spec.ts
index 3b52e50ca..ee1ab9250 100644
--- a/src/modules/status/status.service.spec.ts
+++ b/src/modules/status/status.service.spec.ts
@@ -10,6 +10,7 @@ import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { SendImageStatusDto, SendVideoStatusDto, SendVoiceStatusDto } from './dto/send-media-status.dto';
import { SendPacingService } from '../message/send-pacing.service';
+import { LoggerService } from '../../common/services/logger.service';
describe('StatusService media validation and selection', () => {
const engine = {
@@ -61,6 +62,37 @@ describe('StatusService media validation and selection', () => {
expect(pacing.recordSendFailure).toHaveBeenCalledWith('s1');
expect(pacing.recordSendSuccess).not.toHaveBeenCalled();
});
+
+ // 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 to correlate it with.
+ it('logs the session and kind of a status post the engine refused', async () => {
+ const warn = jest.spyOn(LoggerService.prototype, 'warn').mockImplementation(() => undefined);
+ try {
+ engine.postImageStatus.mockRejectedValueOnce(new Error('upload failed: media entry was not created'));
+ await expect(
+ service.postImageStatus('s1', { base64: 'aGk=', mimetype: 'image/png' }, { recipients: [] }),
+ ).rejects.toThrow('upload failed');
+
+ expect(warn).toHaveBeenCalledWith(
+ 'Status post failed in the engine (image)',
+ expect.objectContaining({ sessionId: 's1', error: 'Error: upload failed: media entry was not created' }),
+ );
+ } finally {
+ warn.mockRestore();
+ }
+ });
+
+ it('logs nothing for a refusal that says nothing about the account', async () => {
+ const warn = jest.spyOn(LoggerService.prototype, 'warn').mockImplementation(() => undefined);
+ try {
+ engine.postTextStatus.mockRejectedValueOnce(new BadRequestException('bad status'));
+ await expect(service.postTextStatus('s1', 'hello', { recipients: [] })).rejects.toThrow('bad status');
+
+ expect(warn).not.toHaveBeenCalled();
+ } finally {
+ warn.mockRestore();
+ }
+ });
});
describe('reading statuses', () => {
diff --git a/src/modules/status/status.service.ts b/src/modules/status/status.service.ts
index cb11945e2..0e5ca56f3 100644
--- a/src/modules/status/status.service.ts
+++ b/src/modules/status/status.service.ts
@@ -7,6 +7,7 @@ import { assertBase64WithinMediaCap, stripBase64DataUri } from '../message/media
import { HookManager, applySendingGate } from '../../core/hooks';
import { SendPacingService, countsTowardSendBreaker } from '../message/send-pacing.service';
import { isMediaUrl } from '../../common/media/media-url';
+import { createLogger } from '../../common/services/logger.service';
/** Stored status media is only ever an image, a video or a voice note; a sender-declared mimetype
* outside that is served as inert octet-stream so the media endpoint can't be turned into active
@@ -27,6 +28,7 @@ const BASE64_TEXT = /^[A-Za-z0-9+/_\-\s]*(?:=+\s*)?$/;
@Injectable()
export class StatusService {
+ private readonly logger = createLogger('StatusService');
// HookManager comes from the @Global() HooksModule, StorageService from the @Global()
// StorageModule — neither needs a module import here.
constructor(
@@ -119,7 +121,11 @@ export class StatusService {
* the adapters run inside the call (Baileys refuses a status with no recipients, a media URL can
* be SSRF-blocked): those say nothing about the account's standing. See countsTowardSendBreaker.
*/
- private async recordedPost(sessionId: string, post: () => Promise<StatusResult>): Promise<StatusResult> {
+ private async recordedPost(
+ sessionId: string,
+ kind: string,
+ post: () => Promise<StatusResult>,
+ ): Promise<StatusResult> {
try {
const result = await post();
this.pacing.recordSendSuccess(sessionId);
@@ -127,6 +133,13 @@ export class StatusService {
} catch (error) {
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 to correlate it with.
+ this.logger.warn(`Status post failed in the engine (${kind})`, {
+ sessionId,
+ error: error instanceof Error ? `${error.name}: ${error.message}` : String(error),
+ ...(error instanceof Error && error.cause instanceof Error ? { cause: error.cause.message } : {}),
+ });
}
throw error;
}
@@ -138,7 +151,7 @@ export class StatusService {
() => new NotFoundException(`Session ${sessionId} not found or not connected`),
);
const gated = await this.gate(sessionId, 'status-text', { text, options });
- return this.recordedPost(sessionId, () => engine.postTextStatus(gated.text, gated.options));
+ return this.recordedPost(sessionId, 'text', () => engine.postTextStatus(gated.text, gated.options));
}
async postImageStatus(
@@ -161,7 +174,9 @@ export class StatusService {
media: { mimetype: mimetype ?? 'image/jpeg', data: base64 || url || '' },
options,
});
- return this.recordedPost(sessionId, () => engine.postImageStatus(this.guardGatedMedia(gated.media), gated.options));
+ return this.recordedPost(sessionId, 'image', () =>
+ engine.postImageStatus(this.guardGatedMedia(gated.media), gated.options),
+ );
}
async postVideoStatus(
@@ -184,7 +199,9 @@ export class StatusService {
media: { mimetype: mimetype ?? 'video/mp4', data: base64 || url || '' },
options,
});
- return this.recordedPost(sessionId, () => engine.postVideoStatus(this.guardGatedMedia(gated.media), gated.options));
+ return this.recordedPost(sessionId, 'video', () =>
+ engine.postVideoStatus(this.guardGatedMedia(gated.media), gated.options),
+ );
}
/**
@@ -217,7 +234,9 @@ export class StatusService {
media: { mimetype: mimetype ?? 'audio/ogg; codecs=opus', data: base64 || url || '' },
options,
});
- return this.recordedPost(sessionId, () => engine.postVoiceStatus(this.guardGatedMedia(gated.media), gated.options));
+ return this.recordedPost(sessionId, 'voice', () =>
+ engine.postVoiceStatus(this.guardGatedMedia(gated.media), gated.options),
+ );
}
async deleteStatus(sessionId: string, statusId: string): Promise<void> {