-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Add info for debugDescription #2700
Conversation
add parameters info for debugDescription of DataResponse and DownloadResponse
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.
Thanks for the PR! Sorry it's taken so long, but we definitely want these changes. I end up writing this manually a lot. You can make the code a lot simpler with my suggestions and I think we should print the response body as well.
Source/Response.swift
Outdated
@@ -88,6 +88,12 @@ extension DataResponse: CustomStringConvertible, CustomDebugStringConvertible { | |||
/// result. | |||
public var debugDescription: String { | |||
let requestDescription = request.map { "\($0.httpMethod!) \($0)" } ?? "nil" | |||
let parameters = { () -> String in |
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.
You can greatly compact this code, and the naming should reflect the fact that it's the body parameters:
let body = request?.httpBody.map { String(decoding: $0, as: UTF8.self) } ?? "None"
...
[Request Body]: \(body)
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.
Thank you for your suggestion
@@ -101,6 +107,7 @@ extension DataResponse: CustomStringConvertible, CustomDebugStringConvertible { | |||
|
|||
return """ | |||
[Request]: \(requestDescription) | |||
[Parameters]: \(parameters) | |||
[Response]: \n\(responseDescription) | |||
[Data]: \(data?.description ?? "None") |
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.
Since you're adding the "Request Body", you should do the same thing here: generate a String
from the response Data
and update this field to be [Response Body]
.
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.
I have added [Response Body]
Source/Response.swift
Outdated
@@ -272,6 +279,12 @@ extension DownloadResponse: CustomStringConvertible, CustomDebugStringConvertibl | |||
/// actions, and the response serialization result. | |||
public var debugDescription: String { | |||
let requestDescription = request.map { "\($0.httpMethod!) \($0)" } ?? "nil" | |||
let parameters = { () -> String in |
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.
Same changes as mentioned earlier.
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.
Looks good, thanks!
add parameters info for debugDescription of DataResponse and DownloadResponse