Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(openapi): describe the channel delete and unsubscribe 404

Yudhi Armyndharisbaeb82fd8432
diff --git a/src/modules/channel/channel.controller.spec.ts b/src/modules/channel/channel.controller.spec.ts
index 47061da7d..bf7e9f307 100644
--- a/src/modules/channel/channel.controller.spec.ts
+++ b/src/modules/channel/channel.controller.spec.ts
@@ -92,3 +92,16 @@ describe('ChannelController OpenAPI 400 responses', () => {
},
);
});
+
+describe('ChannelController OpenAPI 404 on delete and unsubscribe', () => {
+ // Both routes refuse only an id that is not a channel id; neither looks the channel up, so the
+ // subscribed-list "not synced yet" wording would invite a retry that cannot succeed.
+ it.each(['remove', 'unsubscribe'] as const)('%s describes the 404 as a malformed channel id', route => {
+ const responses = Reflect.getMetadata(
+ 'swagger/apiResponse',
+ Object.getOwnPropertyDescriptor(ChannelController.prototype, route)?.value as object,
+ ) as Record<string, { description?: string }>;
+ expect(responses['404']?.description).toContain('@newsletter');
+ expect(responses['404']?.description).not.toContain('synced');
+ });
+});
diff --git a/src/modules/channel/channel.controller.ts b/src/modules/channel/channel.controller.ts
index dcf430f91..237419442 100644
--- a/src/modules/channel/channel.controller.ts
+++ b/src/modules/channel/channel.controller.ts
@@ -16,6 +16,10 @@ import {
ENGINE_REFUSED_403,
} from '../../common/openapi/engine-status-responses';
+/** Delete and unsubscribe refuse a non-channel id up front; neither looks the channel up. */
+const CHANNEL_ID_INVALID_404 =
+ 'The id is not a channel id (it does not end in `@newsletter`). Retrying the same id cannot succeed.';
+
@ApiTags('channels')
@Controller('sessions/:sessionId/channels')
export class ChannelController {
@@ -131,7 +135,7 @@ export class ChannelController {
@ApiResponse({ status: 400, description: 'Session not started' })
@ApiResponse({ status: 403, description: 'The engine refused — not found, or this account does not own it' })
@ApiResponse({ status: 409, description: ENGINE_NOT_READY_409 })
- @ApiResponse({ status: 404, description: CHANNEL_NOT_FOUND_404 })
+ @ApiResponse({ status: 404, description: CHANNEL_ID_INVALID_404 })
async remove(
@Param('sessionId') sessionId: string,
@Param('channelId') channelId: string,
@@ -294,7 +298,7 @@ export class ChannelController {
@ApiResponse({ status: 400, description: 'Session not started' })
@ApiResponse({ status: 409, description: ENGINE_NOT_READY_409 })
@ApiResponse({ status: 403, description: ENGINE_REFUSED_403 })
- @ApiResponse({ status: 404, description: CHANNEL_NOT_FOUND_404 })
+ @ApiResponse({ status: 404, description: CHANNEL_ID_INVALID_404 })
async unsubscribe(@Param('sessionId') sessionId: string, @Param('channelId') channelId: string) {
await this.channelService.unsubscribeFromChannel(sessionId, channelId);
return { success: true };