fix(errors): type server/auth errors and restore type compatibility#1561
fix(errors): type server/auth errors and restore type compatibility#1561workos-sdk-automation[bot] wants to merge 3 commits intomainfrom
Conversation
- Add typed `rawData` (WorkOSErrorData) and `code` property to GenericServerException so callers can inspect error codes without casting (#959, #1204, #1310) - Add AuthenticationException for auth-specific errors like email_verification_required and organization_selection_required - Throw on unrecognized event types in deserializeEvent instead of silently returning undefined (#864)
Greptile SummaryThis PR adds typed error support for server and authentication errors: a new Confidence Score: 5/5Safe to merge; all remaining findings are P2 type-safety suggestions that do not affect runtime correctness. The new src/common/serializers/event.serializer.ts and src/common/interfaces/event.interface.ts — the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[HTTP Error Response] --> B{status code?}
B -->|401| C[UnauthorizedException]
B -->|404| D[NotFoundException]
B -->|409| E[ConflictException]
B -->|422| F[UnprocessableEntityException]
B -->|429| G[RateLimitExceededException]
B -->|default| H{error or error_description?}
H -->|yes| I[OauthException]
H -->|no| J{code && errors?}
J -->|yes| K[BadRequestException]
J -->|no| L{isAuthenticationErrorData?}
L -->|yes - NEW| M[AuthenticationException with pendingAuthenticationToken]
L -->|no| N[GenericServerException with code + rawData]
O[Webhook EventResponse] --> P{event type known?}
P -->|yes| Q[Deserialize to typed Event]
P -->|default - NEW| R[Return UnknownEvent shape as Event cast]
Reviews (2): Last reviewed commit: "fix: address review comments on error ha..." | Re-trigger Greptile |
- Remove redundant this.code assignment in AuthenticationException (already set by GenericServerException) - Make pending_authentication_token optional so auth errors without token still get caught as AuthenticationException - Relax isAuthenticationErrorData guard to match on code alone - Return passthrough object for unrecognized event types instead of throwing (forward-compatible with new server-side events) - Export UnknownEvent interface for consumer reference Co-Authored-By: garen.torikian <garen.torikian@workos.com>
What's changed
WorkOSErrorDataonGenericServerExceptionAuthenticationExceptionplus auth error type guard for known authentication error codesWorkOSResponseErrorstructurally compatible withWorkOSErrorData(index signature) to preserve strict TypeScript compatibilityIssues
Fixes #959
Fixes #864
Refs #1204
Refs #1310