Skip to content

fix: preserve original error when API error body has no error.type - #115

Open
mrKanoh wants to merge 1 commit into
fintoc-com:masterfrom
mrKanoh:fix/preserve-original-http-error
Open

mrKanoh wants to merge 1 commit into
fintoc-com:masterfrom
mrKanoh:fix/preserve-original-http-error

Conversation

@mrKanoh

@mrKanoh mrKanoh commented Nov 6, 2026

Copy link
Copy Markdown

Description

Fixes #19.

canRaiseHTTPError assumed that every HTTP error response carries a body shaped like { error: { type, ... } }. When the response comes from somewhere else (for example a 400 from a proxy or load balancer with a non-JSON body such as 400 Bad Request), response.data.error is undefined and the decorator threw TypeError: Cannot read properties of undefined (reading 'type'). That hid the real HTTP error from the caller.

What changes: the Fintoc error class is only raised when response.data.error is an object whose type is a string. In any other case the original AxiosError is re-thrown unchanged, so its status and response are preserved.

Tests: 8 new cases in src/spec/utils/canRaiseHTTPError.spec.ts. Seven cover bodies without a usable error.type (string, HTML, {}, { error: {} }, non-object error, undefined, null) and expect the original error to be re-thrown; one control checks that a well-formed invalid_request_error body still raises InvalidRequestError. The seven re-throw cases failed with TypeError before the change. yarn build and yarn lint pass, and the suite is at 349 passing (341 before).

Requirements

None.

Additional changes

None. The version is not bumped, as AGENTS.md asks.

🤖 Generated with Claude Code

canRaiseHTTPError assumed response.data.error.type always exists. When the API (or a proxy) answers with a body of another shape, such as a plain-text 400, it threw a TypeError that hid the real HTTP error. Now the Fintoc error is only raised when error.type is a string; otherwise the original error is re-thrown.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mrKanoh
mrKanoh marked this pull request as ready for review November 6, 2026 23:30

@fin-review fin-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Executing fintocClient.links.get generates an axios error

1 participant