From 18828dd1db96f644e34d2a21d0dc10a775ae4b5b Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 11 May 2021 14:37:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/lib/webdav/WebDav.kt | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index 6052e68ff..cb65fc109 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -190,12 +190,13 @@ class WebDav(urlStr: String) { val url = httpUrl val auth = HttpAuth.auth if (url != null && auth != null) { - okHttpClient.newCall { - url(url) - put(fileBody) - addHeader("Authorization", Credentials.basic(auth.user, auth.pass)) - }.close() - return true + return kotlin.runCatching { + okHttpClient.newCall { + url(url) + put(fileBody) + addHeader("Authorization", Credentials.basic(auth.user, auth.pass)) + }.close() + }.isSuccess } return false } @@ -206,12 +207,13 @@ class WebDav(urlStr: String) { val url = httpUrl val auth = HttpAuth.auth if (url != null && auth != null) { - okHttpClient.newCall { - url(url) - put(fileBody) - addHeader("Authorization", Credentials.basic(auth.user, auth.pass)) - }.close() - return true + return kotlin.runCatching { + okHttpClient.newCall { + url(url) + put(fileBody) + addHeader("Authorization", Credentials.basic(auth.user, auth.pass)) + }.close() + }.isSuccess } return false } @@ -220,10 +222,12 @@ class WebDav(urlStr: String) { val url = httpUrl val auth = HttpAuth.auth if (url != null && auth != null) { - return okHttpClient.newCall { - url(url) - addHeader("Authorization", Credentials.basic(auth.user, auth.pass)) - }.byteStream() + return kotlin.runCatching { + okHttpClient.newCall { + url(url) + addHeader("Authorization", Credentials.basic(auth.user, auth.pass)) + }.byteStream() + }.getOrNull() } return null }