Skip to content

feat(errors): add typed error subclasses for each error code (#327) - #350

Merged
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
bukeeastrey:feature/issue-327-typed-error-subclasses
Aug 19, 2026
Merged

feat(errors): add typed error subclasses for each error code (#327)#350
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
bukeeastrey:feature/issue-327-typed-error-subclasses

Conversation

@bukeeastrey

Copy link
Copy Markdown
Contributor

Description

Addresses #327 by introducing a dedicated typed error hierarchy rooted in GuildPassError, providing typed subclasses for every error code defined in errorCodes.ts.

Previously, consumers had to inspect error.code string/enum comparisons to distinguish error types. With these changes, consumers can use idiomatic TypeScript instanceof checks (e.g., if (e instanceof NetworkError) ...) while maintaining full backward compatibility with string-based checks.

Key Changes

  • Base Class (GuildPassError): Extends JavaScript's built-in Error, properly sets the prototype chain for transpiled instanceof checks, and provides support for HTTP status codes, structured details, causes, and JSON serialization.
  • Error Codes (errorCodes.ts): Defined standard error codes and transport codes (NETWORK_ERROR, TIMEOUT_ERROR, CIRCUIT_OPEN, UPSTREAM_ERROR, INVALID_CONFIG, ACCESS_DENIED, UNAUTHORIZED, FORBIDDEN, NOT_FOUND, VALIDATION_ERROR, RATE_LIMIT_EXCEEDED, CONFLICT, INTERNAL_ERROR, CONTRACT_ERROR, INVALID_SIGNATURE, BAD_REQUEST, UNSUPPORTED, and domain not-found codes).
  • Typed Error Subclasses (errorTypes.ts):
    • NetworkError
    • TimeoutError
    • UpstreamError
    • CircuitOpenError
    • InvalidConfigError
    • AccessDeniedError
    • UnauthorizedError
    • ForbiddenError
    • NotFoundError
    • ValidationError
    • RateLimitError (RateLimitExceededError)
    • ConflictError
    • InternalError
    • ContractError
    • InvalidSignatureError
    • BadRequestError
    • UnsupportedError
    • MembershipNotFoundError, GuildNotFoundError, PassNotFoundError
  • Re-exports & Mirroring:
    • Exported all error classes, codes, and types from @guildpass/integration-client.
    • Unified HTTP transport errors in packages/integration-client/src/http/errors.ts and circuitBreaker.ts.
    • Mirrored src/errors/ for consumer convenience.
    • Added test:run alias script to root package.json.

Testing

  • Added unit test suite in packages/integration-client/test/errors.test.js and packages/integration-client/test/errors.test.ts.
  • Verified instanceof Error, instanceof GuildPassError, and instanceof <Subclass> behavior.
  • Verified backward compatibility of .code properties.
  • Verified try ... catch pattern matching using instanceof.
  • Ran pnpm typecheck across all workspace projects (passed with 0 errors).
  • Ran pnpm --filter @guildpass/integration-client test (22/22 tests passing).

Closes #327

@Lakes41
Lakes41 merged commit ae2bf82 into Adamantine-guild:main Aug 19, 2026
1 check passed
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.

Add typed error subclasses for each error code

2 participants