-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance/error handling #219
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…lass This commit includes significant changes to error handling and API response management: 1. Removed Resource class from domain.model 2. Introduced a new Resource sealed class in the ktor module: - Generic type parameters for both success (T) and error (E) types - Success and Error as data classes for better pattern matching 3. Added a new Errors sealed class in the ktor module: - ApiError for API-specific errors with message and code - ExceptionError for general exceptions with message and optional throwable
…`MarketsApiImpl` to use ApiResponse and getApiResponse
…g and Resource wrapper
…` to use new Resource type
Kaaveh
requested changes
Sep 1, 2024
core/ktor/src/main/java/ir/composenews/ktor/ResponseTransformer.kt
Outdated
Show resolved
Hide resolved
VahidGarousi
reviewed
Sep 1, 2024
core/ktor/src/main/java/ir/composenews/ktor/HttpClientExtension.kt
Outdated
Show resolved
Hide resolved
core/ktor/src/main/java/ir/composenews/ktor/ResponseTransformer.kt
Outdated
Show resolved
Hide resolved
- Transferred all contents from core:ktor to the core:network:ktor module Kaaveh#219 (comment)
Kaaveh
approved these changes
Sep 2, 2024
@VahidGarousi are we ready to merge the PR? |
VahidGarousi
approved these changes
Sep 2, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Error Handling Improvement
One of the most significant improvements in this PR is the introduction of a robust and flexible API response handling system using Ktor. This new system provides a more structured and type-safe way to manage API responses and errors.
Key Components:
1. ApiResponse Sealed Interface:
Success<T>
: Represents successful API calls with data. b.Failure.Error
: Represents API errors (e.g., server errors). c.Failure.Exception
: Represents client-side exceptions (e.g., network issues).2. apiResponseOf Function:
ApiResponse
.ApiResponse.Failure.Exception
3. Extension Functions for HttpResponse:
getStatusCode()
: Maps HTTP status codes to our custom StatusCode enum.payloadResponse
andstatusCode
for easier access to error details.4. HttpClient Extensions:
getApiResponse
: Simplifies making GET requests and handling responses.5. ApiResponse Extension Functions:
onSuccess
,onError
,onException
, etc.6. Error Handling:
Resource
class to use the newErrors
typeErrors
types.Benefits of This Approach:
One of Usage Example::
Important Note:
Thank you for your review and feedback.
#205