INTER-1905: strongly type RequestError.errorCode#251
Conversation
🦋 Changeset detectedLatest 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 |
Coverage report
Show new covered files 🐣
Test suite run success79 tests passing in 24 suites. Report generated by 🧪jest coverage report action from b3830ca Show full coverage report
|
There was a problem hiding this comment.
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 RequestErrorwith typederrorCode: ErrorCode, and updatesTooManyRequestsErrorto extendApiError. - Updates
FingerprintServerApiClientto throwApiErrorfor structured Server API errors, and plainRequestErrorfor 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.
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.
fac4534 to
a83ad4b
Compare
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
🚀 Following releases will be created using changesets from this PR:@fingerprint/node-sdk@7.5.0Minor Changes
Patch Changes
|
RequestError.errorCodeasLooseAutocomplete<ErrorCode>(ErrorCode | (string & {})) instead of a free-formstring. Consumers get autocomplete on the Server API error codes, while non-Server-API responses (proxy/LB, viaRequestError.unknown) can still carry an out-of-unionstatusText.ErrorCodetype.main. Ships as aminorchangeset.Scoped down from the original PR
The
ApiError/RequestErrorseparation moved to a follow-up stacked on top: #260.