Skip to content

refactor(errors): separate ServerApiError from RequestError#260

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

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

Conversation

@JuroUhlar

@JuroUhlar JuroUhlar commented Jul 7, 2026

Copy link
Copy Markdown
Contributor
  • Add ServerApiError extends RequestError, thrown for structured Server API error responses; it carries the strongly typed errorCode (ErrorCode) and responseBody: ErrorResponse.
  • TooManyRequestsError now extends ServerApiError.
  • 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.
  • Export the ErrorCode type; consolidate the error-handling changeset into one entry.
  • Remove the base branch's LooseAutocomplete/typeUtils.ts, now superseded (see below).
  • Readme error-handling section updated to show ServerApiError/ErrorCode narrowing.

Supersedes the base's LooseAutocomplete approach

Base #251 kept errorCode on RequestError, widened to LooseAutocomplete<ErrorCode> with a statusText placeholder on the proxy path. This PR instead moves errorCode to ServerApiError only (strictly typed), so RequestError has no errorCode at all. That makes LooseAutocomplete dead code, so it's removed here, and the two error changesets are folded into one coherent entry.

Because this PR reverses part of its base, the stack is only coherent if #251 and this PR merge together. If #251 releases on its own first, we'd ship LooseAutocomplete and then remove it. Consider collapsing the stack (or trimming #251 down to just the ErrorCode export) before merging.

Discussion point: minor vs major

On the non–Server-API (proxy) 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.

Discussion point: class name

Named ServerApiError (vs the previous ApiError) to contrast with RequestError and make the "structured Server API error" meaning explicit. Easy to revert to ApiError if preferred.

@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a639fae

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

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 100% 356/356
🟢 Branches 100% 126/126
🟢 Functions 100% 36/36
🟢 Lines 100% 356/356

Test suite run success

81 tests passing in 24 suites.

Report generated by 🧪jest coverage report action from a639fae

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

@JuroUhlar JuroUhlar force-pushed the refactor/separate-api-errors branch 2 times, most recently from 061290e to 3b91dd0 Compare July 8, 2026 14:26
Introduce ServerApiError (extends RequestError) for structured Server API
error responses, carrying the strongly typed errorCode (ErrorCode).
TooManyRequestsError now extends ServerApiError. 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.

Supersedes the base branch's LooseAutocomplete approach: since errorCode
now lives only on ServerApiError (strictly typed), the widened
errorCode on RequestError and the LooseAutocomplete helper are removed.

Runtime note: on the proxy/unknown path, errorCode previously reflected
response.statusText and is now absent.
@JuroUhlar JuroUhlar force-pushed the refactor/separate-api-errors branch from 3b91dd0 to a639fae Compare July 8, 2026 14:54
@github-actions

github-actions Bot commented Jul 8, 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 and strongly type the error code.

    • Added ServerApiError (extends RequestError), thrown when the Server API returns a structured error response. It exposes a strongly typed errorCode (ErrorCode) and responseBody: ErrorResponse.
    • Exported the ErrorCode type (the union of error codes returned by the Fingerprint Server API).
    • TooManyRequestsError now extends ServerApiError.
    • 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: ServerApiError extends RequestError, so error instanceof RequestError checks keep working. To read the error code, narrow to ServerApiError (if (error instanceof ServerApiError) { 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. (a639fae)

Patch Changes

  • errors: Normalize caught values into real Error instances, so errors from unseal and JSON parsing always carry a genuine Error. (5764c11)

@JuroUhlar JuroUhlar changed the title refactor(errors): separate ApiError from RequestError refactor(errors): separate ServerApiError from RequestError Jul 8, 2026
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