-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Make ResponseDecoder return nullable String type since the usage is r… #1455
Make ResponseDecoder return nullable String type since the usage is r… #1455
Conversation
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.
Hi @huhx, since you've mentioned the transformer, can you add a check to return an encoded body when the response body bytes are not empty? Such as:
String? responseBody;
if (options.responseDecoder != null) {
responseBody = options.responseDecoder!(
responseBytes,
options,
response..stream = Stream.empty(),
);
} else if (responseBytes.isNotEmpty) { // <-- Add this condition to avoid an empty string response.
responseBody = utf8.decode(responseBytes, allowMalformed: true);
}
Also, are you willing to contribute by letting us pick the PR to another community-maintained dio? (We'll announce the new repo later once we merge PRs as much as possible.) Also, it might be better to add some tests.
dio/lib/src/transformer.dart
Outdated
@@ -153,7 +153,7 @@ class DefaultTransformer extends Transformer { | |||
} else { | |||
responseBody = utf8.decode(responseBytes, allowMalformed: true); | |||
} | |||
if (responseBody.isNotEmpty && | |||
if (responseBody !=null && responseBody.isNotEmpty && |
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.
if (responseBody !=null && responseBody.isNotEmpty && | |
if (responseBody != null && | |
responseBody.isNotEmpty && |
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.
sure, and I already add test if options.responseDecoder return null value.
@huhx Can you make a new PR based on the |
👌 |
This PR make the ResponseDecoder return nullable String
In options.dart:
The usage of this function: src/transformer.dart
As we can see the responseBody is nullable, it means
ResponseDecoder
function return String? may be make sense.