Skip to content

refactor(errors): separate ApiError from RequestError#260

Open
JuroUhlar wants to merge 1 commit into
claude/inter-1905-89swu4from
refactor/separate-api-errors
Open

refactor(errors): separate ApiError from RequestError#260
JuroUhlar wants to merge 1 commit into
claude/inter-1905-89swu4from
refactor/separate-api-errors

Conversation

@JuroUhlar

Copy link
Copy Markdown
Contributor
  • Add ApiError extends RequestError, thrown for structured Server API error responses; it carries the strongly typed errorCode (ErrorCode) and responseBody: ErrorResponse.
  • TooManyRequestsError now extends ApiError; the client throws ApiError for structured responses.
  • RequestError becomes the base for request-level errors, thrown directly for non–Server-API responses (e.g. an intermediate proxy). It no longer declares errorCode.
  • Readme error-handling section updated to show ApiError/ErrorCode narrowing.

Stacked on #251

Base is the strongly-typed-errorCode branch (#251). Review/merge #251 first; this PR's diff is only the error separation.

Runtime change: proxy-path errorCode

On the non–Server-API path, errorCode previously reflected response.statusText; it is now absent (undefined). The compiler can't catch this for untyped consumers, so it's a runtime change, not just a type change — flagging against the repo's "runtime API follows semver strictly" note. Shipped as minor; happy to bump to major if preferred.

Introduce ApiError (extends RequestError) for structured Server API error
responses, carrying the strongly typed errorCode. TooManyRequestsError now
extends ApiError. RequestError becomes the base for request-level errors and
is thrown directly for non-Server-API responses (e.g. proxy errors), where no
errorCode is available.

Runtime note: on the proxy/unknown path, errorCode previously reflected
response.statusText and is now absent.
@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8baa87a

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🚀 Following releases will be created using changesets from this PR:

@fingerprint/node-sdk@7.5.0

Minor Changes

  • Separate Server API errors from other request errors.

    • Added ApiError (extends RequestError), thrown when the Server API returns a structured error response. It carries the strongly typed errorCode (ErrorCode) and responseBody: ErrorResponse.
    • TooManyRequestsError now extends ApiError.
    • RequestError is now the base class for request-level errors and is thrown directly for non–Server-API responses (for example, errors returned by an intermediate proxy). It no longer declares errorCode.

    Migration: ApiError extends RequestError, so error instanceof RequestError checks keep working. To read the error code, narrow to ApiError (if (error instanceof ApiError) { error.errorCode }).

    Runtime note: on the non–Server-API (proxy) error path, errorCode previously reflected response.statusText; it is now absent (undefined). This is a runtime change for untyped consumers that read errorCode on such errors, not merely a type change. (8baa87a)

  • Strongly type the RequestError.errorCode field.

    errorCode is now typed as the ErrorCode union (the set of error codes returned by the Fingerprint Server API) instead of a free-form string. The new ErrorCode type is also exported. This is a type-only change; runtime behavior is unchanged. (a83ad4b)

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 100% 346/346
🟢 Branches 100% 115/115
🟢 Functions 100% 36/36
🟢 Lines 100% 346/346

Test suite run success

78 tests passing in 22 suites.

Report generated by 🧪jest coverage report action from 8baa87a

Show full coverage report
St File % Stmts % Branch % Funcs % Lines Uncovered Line #s
🟢 All files 100 100 100 100
🟢  src 100 100 100 100
🔴   ...edApiTypes.ts 0 0 0 0
🟢   index.ts 100 100 100 100
🟢   sealedResults.ts 100 100 100 100
🟢   ...rApiClient.ts 100 100 100 100
🟢   types.ts 100 100 100 100
🟢   urlUtils.ts 100 100 100 100
🟢   webhook.ts 100 100 100 100
🟢  src/errors 100 100 100 100
🟢   apiErrors.ts 100 100 100 100
🟢   ...orResponse.ts 100 100 100 100
🟢   toError.ts 100 100 100 100
🟢   unsealError.ts 100 100 100 100

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant