Skip to content

Major refactory: improved resolver, remote and overall error handling#202

Merged
petruki merged 1 commit intomasterfrom
staging
Jun 27, 2025
Merged

Major refactory: improved resolver, remote and overall error handling#202
petruki merged 1 commit intomasterfrom
staging

Conversation

@petruki
Copy link
Member

@petruki petruki commented Jun 27, 2025

This pull request introduces several significant changes to the codebase, focusing on improving error handling, simplifying result representation, and enhancing the criteria evaluation logic. The most important updates include replacing multiple error classes with a unified ClientError hierarchy, introducing the SwitcherResult class for consistent result representation, and refactoring the criteria evaluation logic to streamline decision-making processes.

Error Handling Improvements:

  • Replaced multiple error classes (AuthError, CriteriaError, SnapshotServiceError, etc.) with a unified ClientError hierarchy for better consistency and maintainability. (src/lib/exceptions/index.js, [1] [2] [3] [4] [5] [6]
  • Added an errorHandler function to centralize error handling logic and ensure non-ClientError instances are wrapped in RemoteError. (src/lib/remote.js, src/lib/remote.jsL174-R183)

Result Representation Enhancements:

  • Introduced the SwitcherResult class to encapsulate the result, reason, and metadata of criteria evaluations, replacing ad-hoc result objects. (src/lib/result.js, src/lib/result.jsR1-R64)
  • Updated methods to return SwitcherResult instances instead of plain objects, improving consistency across the codebase. (src/lib/bypasser/key.js, [1]; src/switcher.js, [2]

Criteria Evaluation Refactoring:

  • Refactored criteria evaluation logic in resolveCriteria, checkGroup, and related methods to simplify decision-making and leverage SwitcherResult for result representation. (src/lib/resolver.js, [1] [2]
  • Improved strategy evaluation by introducing helper methods like checkStrategyConfig and isStrategyFulfilled for better modularity. (src/lib/resolver.js, src/lib/resolver.jsR4-R135)

Miscellaneous Changes:

  • Updated tests to reflect the new error handling and result representation logic. (tests/helper/utils.js, [1] [2]
  • Added a default disabled domain snapshot for testing purposes. (tests/snapshot/default_disabled.json, tests/snapshot/default_disabled.jsonR1-R10)

These changes collectively enhance the codebase's maintainability, readability, and robustness while simplifying error handling and result evaluation.

@petruki petruki self-assigned this Jun 27, 2025
@petruki petruki added the enhancement New feature or request label Jun 27, 2025
@sonarqubecloud
Copy link

@petruki petruki merged commit 25a7096 into master Jun 27, 2025
19 of 20 checks passed
@petruki petruki deleted the staging branch June 27, 2025 01:16
@petruki petruki added this to the v4.3.0 milestone Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant