Skip to content

Commit 477248e

Browse files
committed
fix: Prevent double error logging
1 parent 7a399f0 commit 477248e

1 file changed

Lines changed: 33 additions & 26 deletions

File tree

packages/adapter-whatsapp/src/index.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { createHmac, timingSafeEqual } from "node:crypto";
2-
import { extractCard, ValidationError } from "@chat-adapter/shared";
2+
import {
3+
AdapterError,
4+
extractCard,
5+
ValidationError,
6+
} from "@chat-adapter/shared";
37
import type {
48
Adapter,
59
AdapterPostableMessage,
@@ -978,35 +982,35 @@ export class WhatsAppAdapter
978982
}
979983

980984
if (status) {
981-
this.logger.warn(
982-
"WhatsApp typing indicator ignores custom status text",
983-
{ status, threadId, messageId }
984-
);
985+
this.logger.warn("WhatsApp typing indicator ignores custom status text", {
986+
status,
987+
threadId,
988+
messageId,
989+
});
985990
}
986991

987-
try {
988-
const response = await this.graphApiRequest<WhatsAppTypingIndicatorResponse>(`/${this.phoneNumberId}/messages`, {
989-
messaging_product: "whatsapp",
990-
status: "read",
991-
message_id: messageId,
992-
typing_indicator: {
993-
type: "text",
994-
},
995-
});
992+
const response =
993+
await this.graphApiRequest<WhatsAppTypingIndicatorResponse>(
994+
`/${this.phoneNumberId}/messages`,
995+
{
996+
messaging_product: "whatsapp",
997+
status: "read",
998+
message_id: messageId,
999+
typing_indicator: {
1000+
type: "text",
1001+
},
1002+
}
1003+
);
9961004

997-
if (!response.success) {
998-
this.logger.error("WhatsApp typing indicator failed", {
1005+
if (!response.success) {
1006+
this.logger.error(
1007+
"WhatsApp typing indicator failed: API returned success=false",
1008+
{
9991009
messageId,
10001010
threadId,
1001-
});
1002-
throw new Error("WhatsApp typing indicator failed");
1003-
}
1004-
} catch (error) {
1005-
this.logger.error("WhatsApp typing indicator failed", {
1006-
error,
1007-
messageId,
1008-
threadId,
1009-
});
1011+
}
1012+
);
1013+
throw new AdapterError("WhatsApp typing indicator failed", "whatsapp");
10101014
}
10111015
}
10121016

@@ -1217,7 +1221,10 @@ export class WhatsAppAdapter
12171221
body: errorBody,
12181222
path,
12191223
});
1220-
throw new Error(`WhatsApp API error: ${response.status} ${errorBody}`);
1224+
throw new AdapterError(
1225+
`WhatsApp API error: ${response.status} ${errorBody}`,
1226+
"whatsapp"
1227+
);
12211228
}
12221229

12231230
return response.json() as Promise<T>;

0 commit comments

Comments
 (0)