Skip to content

INTER-1905: strongly type RequestError.errorCode#251

Open
JuroUhlar wants to merge 9 commits into
mainfrom
claude/inter-1905-89swu4
Open

INTER-1905: strongly type RequestError.errorCode#251
JuroUhlar wants to merge 9 commits into
mainfrom
claude/inter-1905-89swu4

Conversation

@JuroUhlar

@JuroUhlar JuroUhlar commented Jul 1, 2026

Copy link
Copy Markdown
Contributor
  • Type RequestError.errorCode as LooseAutocomplete<ErrorCode> (ErrorCode | (string & {})) instead of a free-form string. Consumers get autocomplete on the Server API error codes, while non-Server-API responses (proxy/LB, via RequestError.unknown) can still carry an out-of-union statusText.
  • Export the new ErrorCode type.
  • Type-only change; runtime behavior is identical to main. Ships as a minor changeset.

Scoped down from the original PR

The ApiError / RequestError separation moved to a follow-up stacked on top: #260.

@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b3830ca

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 1, 2026

Copy link
Copy Markdown
Contributor

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 100% 363/363
🟢 Branches 100% 125/125
🟢 Functions 100% 35/35
🟢 Lines 100% 363/363
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢 typeUtils.ts 100% 100% 100% 100%

Test suite run success

79 tests passing in 24 suites.

Report generated by 🧪jest coverage report action from b3830ca

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
🔴   typeUtils.ts 0 0 0 0
🟢   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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors the SDK’s error model to distinguish structured Fingerprint Server API errors from other request failures, and to expose schema-derived (strongly typed) error codes to consumers.

Changes:

  • Introduces ApiError extends RequestError with typed errorCode: ErrorCode, and updates TooManyRequestsError to extend ApiError.
  • Updates FingerprintServerApiClient to throw ApiError for structured Server API errors, and plain RequestError for non-matching error payloads.
  • Updates public exports, docs, and tests to reflect the new error hierarchy and typed error codes.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/unit-tests/serverApiClientTests.spec.ts Adds unit coverage for ApiError typing and for plain RequestError on non-Server-API error shapes.
tests/mocked-responses-tests/updateEventTests.spec.ts Updates mocked-response assertions to expect ApiError.fromErrorResponse(...).
tests/mocked-responses-tests/searchEventsTests.spec.ts Updates mocked-response assertions to expect ApiError.fromErrorResponse(...).
tests/mocked-responses-tests/getEventTests.spec.ts Updates mocked-response assertions to expect ApiError.fromErrorResponse(...) while retaining 429 coverage.
tests/mocked-responses-tests/deleteVisitorDataTests.spec.ts Updates mocked-response assertions to expect ApiError.fromErrorResponse(...) while retaining “bad shape” coverage for RequestError.
src/types.ts Adds exported ErrorCode type alias from the OpenAPI schema.
src/serverApiClient.ts Throws ApiError for structured error responses and keeps TooManyRequestsError for 429.
src/index.ts Re-exports ErrorCode from types.
src/errors/apiErrors.ts Removes errorCode from RequestError, adds ApiError with typed errorCode, and updates TooManyRequestsError inheritance.
readme.md Updates error-handling documentation and example to narrow to ApiError for typed errorCode.
.changeset/strongly-typed-error-codes.md Adds a minor changeset describing the refactor and migration guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/errors/apiErrors.ts Outdated
Comment thread readme.md
Comment thread src/serverApiClient.ts
Type errorCode as the ErrorCode union from the Server API schema instead
of a free-form string, and export the ErrorCode type. Type-only change;
runtime behavior is unchanged.
@JuroUhlar JuroUhlar force-pushed the claude/inter-1905-89swu4 branch from fac4534 to a83ad4b Compare July 7, 2026 14:01
@JuroUhlar JuroUhlar changed the title refactor(errors): use strongly typed error codes and separate API errors refactor(errors): strongly type RequestError.errorCode Jul 7, 2026
@JuroUhlar JuroUhlar requested a review from Copilot July 8, 2026 13:01
@JuroUhlar JuroUhlar changed the title refactor(errors): strongly type RequestError.errorCode INTER-1905: strongly type RequestError.errorCode Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/errors/apiErrors.ts Outdated
Comment thread src/errors/apiErrors.ts Outdated
Comment thread .changeset/strongly-typed-error-codes.md Outdated
@JuroUhlar JuroUhlar requested a review from Copilot July 8, 2026 14:17
@JuroUhlar JuroUhlar marked this pull request as ready for review July 8, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread readme.md Outdated
Clarify in the readme error-handling example that error.errorCode is a
best-effort placeholder (derived from statusText) for non-Server-API
responses such as proxy or load balancer errors, so it may fall outside
the ErrorCode union. Addresses Copilot review feedback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012G93oCegs8kBFqxHRbgkXW
@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

  • Strongly type the RequestError.errorCode field.

    errorCode is now typed as the LooseAutocomplete<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)

Patch Changes

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

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.

3 participants