Skip to content

Commit 2fba70b

Browse files
committed
fix(discord): preserve webhook deadline errors
1 parent 18e107f commit 2fba70b

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎extensions/discord/src/send.webhook.timeout.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ async function expectWebhookTimeout(promise: Promise<unknown>): Promise<void> {
5151
name: "TimeoutError",
5252
message: "request timed out",
5353
});
54-
await vi.advanceTimersByTimeAsync(DISCORD_REST_TIMEOUT_MS);
55-
await rejection;
54+
await Promise.all([vi.advanceTimersByTimeAsync(DISCORD_REST_TIMEOUT_MS), rejection]);
5655
}
5756

5857
describe("sendWebhookMessageDiscord timeout", () => {

‎extensions/discord/src/send.webhook.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ async function throwWebhookResponseError(
7777
response: Response,
7878
signal: AbortSignal | undefined,
7979
): Promise<never> {
80-
const raw = await readResponseTextLimited(response, DISCORD_WEBHOOK_ERROR_BODY_LIMIT_BYTES).catch(
81-
() => {
82-
throwIfWebhookDeadlineExpired(signal);
83-
return "";
84-
},
85-
);
80+
const raw = await readResponseTextLimited(response, DISCORD_WEBHOOK_ERROR_BODY_LIMIT_BYTES, {
81+
// The request deadline owns every body read; a shorter shared idle bound
82+
// would turn a stalled Discord response into the wrong error class.
83+
chunkTimeoutMs: DISCORD_WEBHOOK_TIMEOUT_MS,
84+
}).catch(() => {
85+
throwIfWebhookDeadlineExpired(signal);
86+
return "";
87+
});
8688
const parsed = coerceWebhookErrorBody(raw);
8789
if (response.status === 429) {
8890
throw new RateLimitError(response, {

0 commit comments

Comments
 (0)