Skip to content

Commit

Permalink
HTTPClient: improved log for failed requests
Browse files Browse the repository at this point in the history
Changed this log:
```
[network] DEBUG: ℹ️ API request failed: GET /v1/subscribers/17571811-B0A4-49DC-B326-572E602BF195: Request failed signature verification.
```

To this:
```
[network] DEBUG: ℹ️ API request failed: GET /v1/subscribers/BD9F38FF-33C6-4A77-86F7-6AEA92E6717D (200): Request failed signature verification.
```

This was useful when debugging #2668 and #2659.
  • Loading branch information
NachoSoto committed Jun 16, 2023
1 parent 44608c3 commit 63dea0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Sources/Logging/Strings/NetworkStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum NetworkStrings {

case api_request_started(HTTPRequest)
case api_request_completed(_ request: HTTPRequest, httpCode: HTTPStatusCode)
case api_request_failed(_ request: HTTPRequest, error: NetworkError)
case api_request_failed(_ request: HTTPRequest, httpCode: HTTPStatusCode?, error: NetworkError)
case reusing_existing_request_for_operation(CacheableNetworkOperation.Type, String)
case creating_json_error(error: String)
case json_data_received(dataString: String)
Expand Down Expand Up @@ -53,8 +53,9 @@ extension NetworkStrings: LogMessage {
case let .api_request_completed(request, httpCode):
return "API request completed: \(request.description) (\(httpCode.rawValue))"

case let .api_request_failed(request, error):
return "API request failed: \(request.description): \(error.description)"
case let .api_request_failed(request, statusCode, error):
return "API request failed: \(request.description) (\(statusCode?.rawValue.description ?? "<>")): " +
"\(error.description)"

case let .reusing_existing_request_for_operation(operationType, cacheKey):
return "Network operation '\(operationType)' found with the same cache key " +
Expand Down
4 changes: 3 additions & 1 deletion Sources/Networking/HTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ private extension HTTPClient {
httpCode: urlResponse?.httpStatusCode ?? response.statusCode
))
case let .failure(error):
Logger.debug(Strings.network.api_request_failed(request.httpRequest, error: error))
Logger.debug(Strings.network.api_request_failed(request.httpRequest,
httpCode: urlResponse?.httpStatusCode,
error: error))
}

request.completionHandler?(response)
Expand Down

0 comments on commit 63dea0f

Please sign in to comment.