-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
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") | ||
] |
There was a problem hiding this comment.
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") | ||
] |
There was a problem hiding this comment.
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
hi @kakcy , please help me to take a look on this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
thank you 👍
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
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 theApiClientImpl
class to better handle HTTP responses, the addition of a new error type in theResponseError
enum, and corresponding updates to error handling in theBKTError
class. Additionally, there are new test cases inApiClientTests
andBKTErrorTests
to validate these changes.Here are the most important changes:
Improvements to HTTP response handling:
Bucketeer/Sources/Internal/Remote/ApiClientImpl.swift
: Updated theresponseParser
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 expectedResponse
type.Error handling enhancements:
Bucketeer/Sources/Internal/Remote/ApiClientImpl.swift
: Added a new error caseinvalidJSONResponse
in theResponseError
enum to represent scenarios where the response data cannot be decoded into the expectedResponse
type.Bucketeer/Sources/Public/BKTError.swift
: Updated theBKTError
class to handle the newinvalidJSONResponse
error case from theResponseError
enum.Test case additions:
BucketeerTests/ApiClientTests.swift
: Added new test cases inApiClientTests
to validate the handling of different HTTP response scenarios inApiClientImpl
.BucketeerTests/BKTErrorTests.swift
: Added a new test case inBKTErrorTests
to validate the handling of the newinvalidJSONResponse
error case inBKTError
.