Skip to content
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

fix: .unknow error when handle invalid JSON responses #77

Merged
merged 7 commits into from
Mar 22, 2024

Conversation

duyhungtnn
Copy link
Collaborator

@duyhungtnn duyhungtnn commented Mar 11, 2024

Related to #64
We added some tests to see how the current code handles invalid JSON responses

Changes

Fixed the issue where the status code couldn't be captured when

  • The server responded with an unacceptable code and a nil response body.
  • The server responded with a 2xx status code and an invalid JSON response body.

This pull request introduces several changes to the Bucketeer Swift package, primarily focusing on improving error handling for API responses. The key changes include updates to the ApiClientImpl class to better handle HTTP responses, the addition of a new error type in the ResponseError enum, and corresponding updates to error handling in the BKTError class. Additionally, there are new test cases in ApiClientTests and BKTErrorTests to validate these changes.

Here are the most important changes:

Improvements to HTTP response handling:

  • Bucketeer/Sources/Internal/Remote/ApiClientImpl.swift: Updated the responseParser closure to handle different scenarios of HTTP responses more accurately. This includes handling cases where the HTTP response is not available, the status code is not within the acceptable range, or the response data is not available or cannot be decoded into the expected Response type.

Error handling enhancements:

Test case additions:

@duyhungtnn duyhungtnn self-assigned this Mar 11, 2024
ResponseCase(statusCode:500, data: Data("".utf8), name: "Case: empty string"),
ResponseCase(statusCode:500, data: Data("okay".utf8), name: "Case: random string"),
ResponseCase(statusCode:500, data: nil, name: "Case: Nil")
]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed

  • Case: nil response body

ResponseCase(statusCode:200, data: Data("".utf8), name: "Case: empty string"),
ResponseCase(statusCode:201, data: Data("okay".utf8), name: "Case: random string"),
ResponseCase(statusCode:200, data: nil, name: "Case: Nil")
]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed

  • Case: empty string response body
  • Case: random string response body
  • Case: nil response body

@duyhungtnn duyhungtnn changed the title add: test cases to find source of .unknow error chore: test cases to find source of .unknow error Mar 11, 2024
@duyhungtnn duyhungtnn changed the title chore: test cases to find source of .unknow error fix: .unknow error when handle invalid JSON responses Mar 11, 2024
@duyhungtnn
Copy link
Collaborator Author

hi @kakcy , please help me to take a look on this PR

Copy link
Contributor

@kakcy kakcy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
thank you 👍

@cre8ivejp cre8ivejp merged commit ff7cec6 into main Mar 22, 2024
9 checks passed
@cre8ivejp cre8ivejp deleted the fix/find-source-of-unknow-error branch March 22, 2024 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants