Enhance parse_response
Method to Improve Error Handling and Logging
#153
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.
Description
This pull request introduces significant improvements and fixes to the Checkout Ruby SDK, focusing on error handling, response parsing, and code readability.
Key Changes
Refactored Method Definitions:
Enhanced Error Handling:
CheckoutApiException
to include detailed error messages and structured error details.parse_error_details
to gracefully handle invalid JSON and added robust logging for unexpected exceptions.Improved Response Parsing:
parse_body
to manage responses based on their content type (JSON, CSV, or plain text).parse_response
logic to handle various response formats and edge cases effectively.Added Comprehensive Tests:
api_client_spec.rb
cover:New Klarna Payment Context Handling:
create_payment_contexts_klarna
in the helper for better Klarna-related test coverage.General Improvements:
build_multipart_request
to improve parameter formatting and consistency.contexts_integration_spec.rb
andreports_integration_spec.rb
.Motivation
This PR addresses an identified issue where error responses (HTTP status code > 400) were not logged, creating challenges for debugging. It aims to enhance the SDK's robustness, improve error visibility, and make the code more maintainable.
User Feedback
This PR directly responds to the above feedback by addressing logging and error handling gaps.
Testing
Unit Tests:
api_client_spec.rb
.Integration Tests:
contexts_integration_spec.rb
andreports_integration_spec.rb
to validate changes in response handling and error logging.