WebDav创建目录时添加try防止报错

pull/981/head
gedoor 4 years ago
parent 90fd0d1a59
commit 60fb0d385d
  1. 15
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt

@ -144,19 +144,20 @@ class WebDav(urlStr: String) {
/**
* 根据自己的URL在远程处创建对应的文件夹
*
* @return 是否创建成功
*/
suspend fun makeAsDir(): Boolean {
val url = httpUrl
val auth = HttpAuth.auth
if (url != null && auth != null) {
okHttpClient.newCall {
url(url)
method("MKCOL", null)
addHeader("Authorization", Credentials.basic(auth.user, auth.pass))
}
return true
//防止报错
return kotlin.runCatching {
okHttpClient.newCall {
url(url)
method("MKCOL", null)
addHeader("Authorization", Credentials.basic(auth.user, auth.pass))
}
}.isSuccess
}
return false
}

Loading…
Cancel
Save