Skip to content

result.error is undefined but server returned 429 response #2531

@pesterhazy

Description

@pesterhazy

openapi-typescript version

0.14.0

Node.js version

v22.20.0

OS + version

macOS 15.5

Description

I had to apply this patch to get proper error handling:

-    const { data, error } = await this.client.POST(`/invitees`, {
+    const { data, error, response } = await this.client.POST(`/invitees`, {
       body,
     });
     if (error) {
       throw new ExInfo(`Error: ${error.message}`, {
         data: { details: error.details },
         cause: error,
       });
     }
+    if (!response.ok) {
+      throw new ExInfo(`Error: ${response.statusText}`, {
+        data: { details: response.statusText },
+        cause: response.statusText,
+      });
+    }

The reason is that error is sometimes undefined even though the server returned 4xx - specifically if the 4xx response is not mentioned in the openapi schema.

This happens with 429 Rate Limited errors which get added by Cloudflare (but not to the api spec).

Reproduction

Server response doesn't mention 429 error. Server returns 429 with no response body

Expected result

either

  • error is set to some value
  • the docs state that you need to ALSO check response.ok

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions