-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Bugfix/getuploadcount #3049
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
Bugfix/getuploadcount #3049
Conversation
* response.body().string() was called more than once and because response body can be huge so OkHttp doesnot store it in memory, it reads it as a stream from network when we need it, which cannot be done without a new request.
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.
✅ A review job has been created and sent to the PullRequest network.
Check the status or cancel PullRequest code review here.
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.
Could you please add tests to make sure this change works as expected?
|
Hi @ashishkumar468 I get this error: Is this expected? |
|
It is not, I will look into it, thanks for testing this out @neslihanturan |
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(null!=responseBody) { | ||
| String responseBodyString = responseBody.toString(); | ||
| if (!TextUtils.isEmpty(responseBodyString.trim())) { | ||
| return Integer.parseInt(responseBodyString.trim()); |
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.
Note that this will throw a NumberFormatException if the response body is not actually a number. It might be okay to allow this to just throw, but if crashing is undesired you could use a try/catch and return 0 in the catch.
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.
Added a catch for NumberFormatException
| return Integer.parseInt(response.body().string().trim()); | ||
| ResponseBody responseBody = response.body(); | ||
| if(null!=responseBody) { | ||
| String responseBodyString = responseBody.toString(); |
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.
It could be cleaner to set responseBodyString to responseBody.toString().trim(), since you call trim() in both places that it's used below.
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.
Done
|
@neslihanturan I have handled the exception as well. Please look into it now :-) |
Codecov Report
@@ Coverage Diff @@
## master #3049 +/- ##
=========================================
+ Coverage 4.41% 4.66% +0.24%
=========================================
Files 259 264 +5
Lines 12309 12359 +50
Branches 1056 1052 -4
=========================================
+ Hits 544 577 +33
- Misses 11726 11739 +13
- Partials 39 43 +4
Continue to review full report at Codecov.
|
Description (required)
Fixes #3048
What changes did you make and why?
Extracted out response.body().string() to a variable and used that for further references.
Tests performed (required)
Tested betaDebug on Pixel Api 27