From 263642e863afd8bd572082ed0ba8f555c236c957 Mon Sep 17 00:00:00 2001 From: Jack Williams <1736957+jpwilliams@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:01:53 +0000 Subject: [PATCH 1/2] Do not reuse the response body when parsing errors --- packages/inngest/src/components/Inngest.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/inngest/src/components/Inngest.ts b/packages/inngest/src/components/Inngest.ts index 62069c6d..f4d0e8fb 100644 --- a/packages/inngest/src/components/Inngest.ts +++ b/packages/inngest/src/components/Inngest.ts @@ -318,6 +318,7 @@ export class Inngest { */ private async getResponseError( response: globalThis.Response, + rawBody: unknown, foundErr = "Unknown error" ): Promise { let errorMessage = foundErr; @@ -337,7 +338,7 @@ export class Inngest { errorMessage = "Event key not found"; break; case 406: - errorMessage = `${JSON.stringify(await response.json())}`; + errorMessage = `${JSON.stringify(await rawBody)}`; break; case 409: case 412: @@ -350,7 +351,11 @@ export class Inngest { errorMessage = "Internal server error"; break; default: - errorMessage = await response.text(); + try { + errorMessage = await response.text(); + } catch (err) { + errorMessage = `${JSON.stringify(await rawBody)}`; + } break; } } @@ -558,17 +563,18 @@ export class Inngest { headers: { ...this.headers, ...headers }, }); + let rawBody: unknown; let body: SendEventResponse | undefined; try { - const rawBody: unknown = await response.json(); + rawBody = await response.json(); body = await sendEventResponseSchema.parseAsync(rawBody); } catch (err) { - throw await this.getResponseError(response); + throw await this.getResponseError(response, rawBody); } if (body.status / 100 !== 2 || body.error) { - throw await this.getResponseError(response, body.error); + throw await this.getResponseError(response, rawBody, body.error); } return await applyHookToOutput({ result: { ids: body.ids } }); From a0a6316e4be0d3abdd85526255acf2c1e9cb99c0 Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Mon, 25 Nov 2024 15:55:20 +0000 Subject: [PATCH 2/2] Create chilly-chairs-jog.md --- .changeset/chilly-chairs-jog.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilly-chairs-jog.md diff --git a/.changeset/chilly-chairs-jog.md b/.changeset/chilly-chairs-jog.md new file mode 100644 index 00000000..e700994d --- /dev/null +++ b/.changeset/chilly-chairs-jog.md @@ -0,0 +1,5 @@ +--- +"inngest": patch +--- + +Fix rare body reuse when parsing failure returns from `inngest.send()` and `step.sendEvent()`