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

HTTPClient: log actual response status code #2487

Merged
merged 2 commits into from
May 15, 2023

Conversation

NachoSoto
Copy link
Contributor

We were currently logging the status code retrieved from ETagManager, which made it seem like etags weren't working.

Example:

API request completed: GET /v1/subscribers/identify (200)

With this change, we now log the actual response status code so we can verify the server is returning the correct status code:

API request completed: GET /v1/subscribers/identify (304)

We were currently logging the status code retrieved from `ETagManager`, which made it seem like etags weren't working.

Example:
> API request completed: GET /v1/subscribers/identify (200)

With this change, we now log the actual response status code so we can verify the server is returning the correct status code:
> API request completed: GET /v1/subscribers/identify (304)
@NachoSoto NachoSoto added the test label May 15, 2023
@NachoSoto NachoSoto requested a review from a team May 15, 2023 17:50
@codecov
Copy link

codecov bot commented May 15, 2023

Codecov Report

Merging #2487 (051b9ee) into main (06f80c3) will increase coverage by 1.02%.
The diff coverage is 89.70%.

❗ Current head 051b9ee differs from pull request most recent head dc148e4. Consider uploading reports for the commit dc148e4 to get more accurate results

@@            Coverage Diff             @@
##             main    #2487      +/-   ##
==========================================
+ Coverage   86.64%   87.67%   +1.02%     
==========================================
  Files         195      197       +2     
  Lines       13056    13303     +247     
==========================================
+ Hits        11313    11664     +351     
+ Misses       1743     1639     -104     
Impacted Files Coverage Δ
...onExtensions/DispatchTimeInterval+Extensions.swift 94.91% <ø> (-5.09%) ⬇️
Sources/Misc/Concurrency/Purchases+async.swift 10.52% <0.00%> (ø)
Sources/Misc/Deprecations.swift 38.68% <ø> (ø)
...Purchasing/StoreKitAbstractions/StoreProduct.swift 72.85% <0.00%> (-1.06%) ⬇️
...s/Logging/Strings/OfflineEntitlementsStrings.swift 71.42% <33.33%> (-28.58%) ⬇️
...OfflineEntitlements/PurchasedProductsFetcher.swift 84.61% <84.61%> (ø)
Sources/Purchasing/Purchases/Purchases.swift 76.62% <85.56%> (+1.37%) ⬆️
...s/Purchasing/Purchases/PurchasesOrchestrator.swift 86.36% <91.66%> (+0.26%) ⬆️
...rces/OfflineEntitlements/PurchasedSK2Product.swift 92.85% <92.85%> (ø)
...ntitlements/CustomerInfo+OfflineEntitlements.swift 92.98% <92.98%> (ø)
... and 31 more

... and 36 files with indirect coverage changes

Logger.debug(Strings.network.api_request_completed(request.httpRequest, httpCode: response.statusCode))
Logger.debug(Strings.network.api_request_completed(
request.httpRequest,
httpCode: urlResponse?.httpStatusCode ?? response.statusCode
Copy link
Member

Choose a reason for hiding this comment

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

let's add a comment, it's not obvious at a glance why we're checking them in this order

Copy link
Member

Choose a reason for hiding this comment

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

or make it a method with a clear name or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup good point 👍🏻

var httpStatusCode: HTTPStatusCode? {
guard let response = self as? HTTPURLResponse else { return nil }

return .init(rawValue: response.statusCode)
Copy link
Member

Choose a reason for hiding this comment

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

[nitpick, FFTI] it might just be me, but I find this pattern in general to be less readable than

    return HTTPStatusCode(rawValue: response.statusCode)

since I have to do a double-take and check what the return type of the method is to figure out what we're creating

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's definitely a tradeoff, especially for more complex functions where the context of the type might be lost to the reader. In this particular case my thinking is just "let the compiler figure it out".

@NachoSoto NachoSoto enabled auto-merge (squash) May 15, 2023 23:14
@NachoSoto NachoSoto merged commit d68ca88 into main May 15, 2023
@NachoSoto NachoSoto deleted the http-client-status-code-log branch May 15, 2023 23:28
NachoSoto added a commit that referenced this pull request May 25, 2023
We were currently logging the status code retrieved from `ETagManager`,
which made it seem like etags weren't working.

Example:
> API request completed: GET /v1/subscribers/identify (200)

With this change, we now log the actual response status code so we can
verify the server is returning the correct status code:
> API request completed: GET /v1/subscribers/identify (304)
This was referenced May 31, 2023
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.

2 participants