Difficulty: Intermediate
Type: Refactor
Recommended labels (if available in this repo): enhancement, dx, sdk
Background
src/errors/errorCodes.ts defines error codes and src/errors/GuildPassError.ts provides a base error class, but consumers currently have to check error.code manually to distinguish error types rather than using instanceof checks against specific error classes.
Problem
Without typed subclasses, catching specific error conditions (e.g. NetworkError vs InvalidConfigError vs AccessDeniedError) requires string/enum comparisons scattered through consumer code, which is error-prone and not very ergonomic TypeScript.
Expected Outcome
Each entry in errorCodes.ts has a corresponding typed subclass of GuildPassError (e.g. class NetworkError extends GuildPassError), all exported from src/errors/index.ts (or equivalent), so consumers can do catch (e) { if (e instanceof NetworkError) ... }.
Suggested Implementation
Generate or hand-write one subclass per error code, ensuring each still carries the same code field for backward compatibility with existing string-based checks. Update internal throw sites in src/errors/errorTypes.ts and call sites across src/ to throw the new subclasses instead of the generic base class where applicable.
Acceptance Criteria
- Every error code in
errorCodes.ts has a matching typed subclass
- All subclasses remain
instanceof GuildPassError and retain the code property for backward compatibility
- Existing throw sites updated to use the specific subclasses
- Unit tests verify
instanceof checks work correctly for each subclass
pnpm test:run and pnpm typecheck pass
Likely Affected Files/Directories
src/errors/GuildPassError.ts
src/errors/errorCodes.ts
src/errors/errorTypes.ts
src/errors/error.types.ts
Difficulty: Intermediate
Type: Refactor
Recommended labels (if available in this repo):
enhancement,dx,sdkBackground
src/errors/errorCodes.tsdefines error codes andsrc/errors/GuildPassError.tsprovides a base error class, but consumers currently have to checkerror.codemanually to distinguish error types rather than usinginstanceofchecks against specific error classes.Problem
Without typed subclasses, catching specific error conditions (e.g.
NetworkErrorvsInvalidConfigErrorvsAccessDeniedError) requires string/enum comparisons scattered through consumer code, which is error-prone and not very ergonomic TypeScript.Expected Outcome
Each entry in
errorCodes.tshas a corresponding typed subclass ofGuildPassError(e.g.class NetworkError extends GuildPassError), all exported fromsrc/errors/index.ts(or equivalent), so consumers can docatch (e) { if (e instanceof NetworkError) ... }.Suggested Implementation
Generate or hand-write one subclass per error code, ensuring each still carries the same
codefield for backward compatibility with existing string-based checks. Update internal throw sites insrc/errors/errorTypes.tsand call sites acrosssrc/to throw the new subclasses instead of the generic base class where applicable.Acceptance Criteria
errorCodes.tshas a matching typed subclassinstanceof GuildPassErrorand retain thecodeproperty for backward compatibilityinstanceofchecks work correctly for each subclasspnpm test:runandpnpm typecheckpassLikely Affected Files/Directories
src/errors/GuildPassError.tssrc/errors/errorCodes.tssrc/errors/errorTypes.tssrc/errors/error.types.ts