Define a hierarchy of error classes #196
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Defines a hierarchy of error classes for the SDK. All errors descend from Square::Errors::ApiError, and it currently has two direct descendants:
The subclass approach lets SDK users handle errors as granularly as they like:
Other notes:
Net::HTTPRequestTimeout->Square::Errors::TimeoutErrorconversion might seem pointless, but I'd like to maintain the ability to swap out Net::HTTP for a different networking layer in the future if we want to, and in that case it'll be an easier transition for SDK users if they're handlingSquare::Errors::TimeoutErrorrather thanNet::HTTPRequestTimeoutdirectly.Square::Errorsmodule to group our error classes in - we could leave them at the top level (Square::TimeoutError, etc) but I think that that pollutes theSquaremodule namespace, which is already being populated by many autogenerated classes. I thinkErrorsmakes sense as a grouping of user-exposed classes (similar to the way we currently useSquare::Types) but I'm happy to be persuaded otherwise.Square::Types::Error), providing the tooling to parse and utilize its information in the SDK's error classes is complicated and outside the scope of this PR.