Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(group): report a partial settings failure without engine text
Yudhi Armyndharisbda476428286
diff --git a/src/modules/group/group.service.spec.ts b/src/modules/group/group.service.spec.tsindex 2cc64320c..50db54ea3 100644--- a/src/modules/group/group.service.spec.ts+++ b/src/modules/group/group.service.spec.ts@@ -314,6 +314,26 @@ describe('GroupService', () => {).rejects.toBeInstanceOf(EngineRefusedError);expect(engine.setGroupMessagesAdminsOnly).not.toHaveBeenCalled();});++ it.each([+ ['an Error', new Error('Protocol error (Runtime.callFunctionOn): Target closed at /srv/app/page.js')],+ ['a non-Error value', 'raw-engine-text'],+ ])('reports a partial apply after %s as an internal error without its text', async (_label, raw) => {+ const engine = {+ setGroupEphemeral: jest.fn().mockResolvedValue(undefined),+ setGroupMessagesAdminsOnly: jest.fn().mockRejectedValue(raw),+ };+ const svc = makeService(engine);+ const error = await svc+ .updateGroupSettings('s1', 'g1', { announce: true, ephemeralSeconds: 86400 })+ .catch((e: unknown) => e);+ expect(error).toBeInstanceOf(HttpException);+ const { message } = error as HttpException;+ expect((error as HttpException).getStatus()).toBe(500);+ expect(message).toContain("'announce' failed (internal error)");+ expect(message).toContain('already applied: ephemeralSeconds');+ expect(message).not.toMatch(/Protocol error|\/srv\/app|raw-engine-text/);+ });});});diff --git a/src/modules/group/group.service.ts b/src/modules/group/group.service.tsindex 2423ee370..c37c65118 100644--- a/src/modules/group/group.service.ts+++ b/src/modules/group/group.service.ts@@ -7,6 +7,7 @@ import { isAddressableParticipant } from '../../engine/identity/wa-id';import { SetGroupPictureDto } from './dto/group.dto';import { paginate, ListOptions } from '../../common/utils/paginate';import { SendPacingService } from '../message/send-pacing.service';+import { createLogger } from '../../common/services/logger.service';/*** Owns engine access for group operations. Controllers depend on this service instead of@@ -15,6 +16,8 @@ import { SendPacingService } from '../message/send-pacing.service';*/@Injectable()export class GroupService {+ private readonly logger = createLogger('GroupService');+constructor(private readonly engines: EngineRegistry,private readonly pacing: SendPacingService,@@ -234,7 +237,9 @@ export class GroupService {* A failure on the FIRST applied field propagates unchanged (nothing was applied, so the patch* simply failed). A failure on a LATER field means the group is now in a mixed state, so the* error names the failed field and the ones already applied — the caller can reconcile instead- * of guessing which subset took effect. The wrapped error keeps the underlying HTTP status.+ * of guessing which subset took effect. The wrapped error keeps the underlying HTTP status, and+ * carries the underlying message only for an HTTP error; any other failure is logged here and+ * reported as an internal error.*/async updateGroupSettings(sessionId: string,@@ -277,7 +282,16 @@ export class GroupService {} catch (error) {if (applied.length === 0) throw error;const status = error instanceof HttpException ? error.getStatus() : HttpStatus.INTERNAL_SERVER_ERROR;- const detail = error instanceof Error ? error.message : String(error);+ let detail = 'internal error';+ if (error instanceof HttpException) {+ detail = error.message;+ } else {+ this.logger.error(+ 'Group settings step failed after a partial apply',+ error instanceof Error ? error.stack : String(error),+ { sessionId, groupId, field, applied: applied.join(',') },+ );+ }throw new HttpException(`Group settings only partially applied: '${field}' failed (${detail}); already applied: ${applied.join(', ',