-
Notifications
You must be signed in to change notification settings - Fork 95
Fix exception handling in NextcloudClient #394
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
Fix exception handling in NextcloudClient #394
Conversation
| return method.execute(this) | ||
| } | ||
|
|
||
| @Throws(IOException::class) |
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.
@tobiasKaminsky This will proably break clients, but since IOException is checked, it must be handled.
There is no API to return valid Response in case of error, as OkHttp3 use exceptions to signal abnormal condition. We should follow.
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.
Hm. I would go instead with try/catch so that we can return our own error code.
After all, this is in our library and also should only be called within the library.
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 wrapped the exception in a union-like object.
6276eef to
31a41df
Compare
|
|
||
| class NextcloudClient(var baseUri: Uri, val context: Context) { | ||
| class NextcloudClient(var baseUri: Uri, val context: Context, client: OkHttpClient) { | ||
| lateinit var credentials: String |
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.
Misused lateinit. This should be initialized here. I'll open another ticket for this, tho.
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.
This is fixed via #396
|
@tobiasKaminsky Could you pealse check the method annotated with |
Codecov Report
@@ Coverage Diff @@
## master #394 +/- ##
==========================================
+ Coverage 37% 37.24% +0.24%
==========================================
Files 133 134 +1
Lines 5737 5751 +14
Branches 751 751
==========================================
+ Hits 2123 2142 +19
+ Misses 3289 3285 -4
+ Partials 325 324 -1
|
31a41df to
78ec45a
Compare
tobiasKaminsky
left a comment
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.
Extract ResponseOrError
| val client: OkHttpClient | ||
| val client = client | ||
|
|
||
| data class ResponseOrError private constructor(val result: Response?, val error: Exception?) { |
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.
Nice approach 👍
To not have too many things in one class, can we extract this into its own class?
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.
extracted
78ec45a to
eb51e04
Compare
eb51e04 to
220afbb
Compare
|
@tobiasKaminsky I made the |
Fixes #393 Fixes nextcloud/android#5245 Fixes nextcloud/android#5305 Fixes nextcloud/android#5310 Fixes nextcloud/android#5331 Fixes nextcloud/android#5333 Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
220afbb to
803df96
Compare
Lint
SpotBugs (new)
SpotBugs (master)
|
Should be fine, I currently cannot imagine why we need this outside our lib, but we can still change it later, if required. |
Fixes #393
Fixes nextcloud/android#5245
Fixes nextcloud/android#5305
Fixes nextcloud/android#5310
Fixes nextcloud/android#5331
Fixes nextcloud/android#5333
Fixes nextcloud/android#5390
Signed-off-by: Chris Narkiewicz hello@ezaquarii.com