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

Documented HTTPStatusCode.isSuccessfullySynced #2661

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/Networking/HTTPClient/HTTPStatusCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum HTTPStatusCode {
case notModified
case temporaryRedirect
case invalidRequest
case unauthorized
case notFoundError
case internalServerError
case networkConnectTimeoutError
Expand All @@ -35,6 +36,7 @@ enum HTTPStatusCode {
.notModified,
.temporaryRedirect,
.invalidRequest,
.unauthorized,
.notFoundError,
.internalServerError,
.networkConnectTimeoutError
Expand All @@ -56,6 +58,7 @@ extension HTTPStatusCode: RawRepresentable {
case .notModified: return 304
case .temporaryRedirect: return 307
case .invalidRequest: return 400
case .unauthorized: return 401
case .notFoundError: return 404
case .internalServerError: return 500
case .networkConnectTimeoutError: return 599
Expand Down Expand Up @@ -88,7 +91,12 @@ extension HTTPStatusCode {
return 500...599 ~= self.rawValue
}

/// Used to determine if we can consider subscriber attributes as synced.
/// - Note: whether to finish transactions is determined based on `isServerError` instead.
var isSuccessfullySynced: Bool {
// Note: this means that all 4xx (except 404) are considered as successfully synced.
// The reason is because it's likely due to a client error, so continuing to retry
// won't yield any different results and instead kill pandas.
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this seems to be the same in Android

return !(self.isServerError || self == .notFoundError)
}

Expand Down
3 changes: 3 additions & 0 deletions Tests/UnitTests/Networking/HTTPStatusCodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class HTTPStatusCodeTests: TestCase {

func testIsNotSuccessfulResponse() {
expect(HTTPStatusCode.invalidRequest.isSuccessfulResponse) == false
expect(HTTPStatusCode.unauthorized.isSuccessfulResponse) == false
expect(HTTPStatusCode.notFoundError.isSuccessfulResponse) == false
expect(HTTPStatusCode.internalServerError.isSuccessfulResponse) == false
expect(HTTPStatusCode.networkConnectTimeoutError.isSuccessfulResponse) == false
Expand All @@ -76,6 +77,7 @@ class HTTPStatusCodeTests: TestCase {
expect(HTTPStatusCode.notModified.isServerError) == false
expect(HTTPStatusCode.temporaryRedirect.isServerError) == false
expect(HTTPStatusCode.invalidRequest.isServerError) == false
expect(HTTPStatusCode.unauthorized.isServerError) == false
expect(HTTPStatusCode.notFoundError.isServerError) == false
expect(status(100).isServerError) == false
expect(status(202).isServerError) == false
Expand All @@ -91,6 +93,7 @@ class HTTPStatusCodeTests: TestCase {
expect(HTTPStatusCode.notModified.isSuccessfullySynced) == true
expect(HTTPStatusCode.temporaryRedirect.isSuccessfullySynced) == true
expect(HTTPStatusCode.invalidRequest.isSuccessfullySynced) == true
NachoSoto marked this conversation as resolved.
Show resolved Hide resolved
expect(HTTPStatusCode.unauthorized.isSuccessfullySynced) == true
expect(status(100).isSuccessfullySynced) == true
expect(status(202).isSuccessfullySynced) == true
expect(status(226).isSuccessfullySynced) == true
Expand Down
1 change: 1 addition & 0 deletions Tests/UnitTests/Networking/NetworkErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class NetworkErrorTests: TestCase {

func testSuccessfullySyncedTrue() {
let errors = [
error(Self.responseError(.unauthorized)),
error(Self.responseError(.invalidRequest)),
error(Self.responseError(.notModified)),
error(Self.responseError(.success))
Expand Down