Skip to content

Conversation

@ezaquarii
Copy link
Contributor

@ezaquarii ezaquarii commented Feb 3, 2020

return method.execute(this)
}

@Throws(IOException::class)
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@ezaquarii ezaquarii force-pushed the ezaquarii/fix-nextcloud-client-exception-handling branch from 6276eef to 31a41df Compare February 3, 2020 22:35

class NextcloudClient(var baseUri: Uri, val context: Context) {
class NextcloudClient(var baseUri: Uri, val context: Context, client: OkHttpClient) {
lateinit var credentials: String
Copy link
Contributor Author

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.

Copy link
Member

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

@ezaquarii
Copy link
Contributor Author

ezaquarii commented Feb 3, 2020

@tobiasKaminsky Could you pealse check the method annotated with @Throws? I won't have bandwidth to do it now. I guess some client must be fixed to handle the IOException.

@codecov
Copy link

codecov bot commented Feb 3, 2020

Codecov Report

Merging #394 into master will increase coverage by 0.24%.
The diff coverage is 90.9%.

@@            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
Impacted Files Coverage Δ
.../main/java/com/nextcloud/common/NextcloudClient.kt 50% <100%> (+11.11%) ⬆️
.../main/java/com/nextcloud/common/ResponseOrError.kt 100% <100%> (ø)
...main/java/com/nextcloud/common/OkHttpMethodBase.kt 57.14% <62.5%> (+4.01%) ⬆️
...d/lib/common/operations/RemoteOperationResult.java 42.07% <0%> (+0.3%) ⬆️
...wncloud/android/lib/resources/files/FileUtils.java 85.71% <0%> (+14.28%) ⬆️

Copy link
Member

@tobiasKaminsky tobiasKaminsky left a 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?) {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted

@nextcloud nextcloud deleted a comment from ezaquarii Feb 5, 2020
@ezaquarii ezaquarii force-pushed the ezaquarii/fix-nextcloud-client-exception-handling branch from 78ec45a to eb51e04 Compare February 5, 2020 22:14
@ezaquarii ezaquarii force-pushed the ezaquarii/fix-nextcloud-client-exception-handling branch from eb51e04 to 220afbb Compare February 6, 2020 06:31
@ezaquarii
Copy link
Contributor Author

@tobiasKaminsky I made the okhttp3 execute() request internal. Please confirm if this is what we can do, ie. we don't plan to use it outside the library.

@ezaquarii ezaquarii force-pushed the ezaquarii/fix-nextcloud-client-exception-handling branch from 220afbb to 803df96 Compare February 6, 2020 16:18
@nextcloud-android-bot
Copy link
Collaborator

Lint

TypemasterPR
Warnings00
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings14
Correctness Warnings39
Internationalization Warnings6
Malicious code vulnerability Warnings7
Multithreaded correctness Warnings3
Performance Warnings17
Security Warnings1
Dodgy code Warnings58
Total145

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings14
Correctness Warnings39
Internationalization Warnings6
Malicious code vulnerability Warnings7
Multithreaded correctness Warnings3
Performance Warnings17
Security Warnings1
Dodgy code Warnings58
Total145

@tobiasKaminsky
Copy link
Member

@tobiasKaminsky I made the okhttp3 execute() request internal. Please confirm if this is what we can do, ie. we don't plan to use it outside the library.

Should be fine, I currently cannot imagine why we need this outside our lib, but we can still change it later, if required.

@tobiasKaminsky tobiasKaminsky merged commit e8f50d6 into master Feb 7, 2020
@delete-merged-branch delete-merged-branch bot deleted the ezaquarii/fix-nextcloud-client-exception-handling branch February 7, 2020 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants