Commit 2c7523be authored by Ricki Hirner's avatar Ricki Hirner

Add ForbiddenException and some static Errors (original patch from Matt Jacobsen, thanks)

parent cad85fee
Pipeline #41021548 passed with stages
in 7 minutes and 9 seconds
...@@ -29,4 +29,5 @@ Email: [play@bitfire.at](mailto:play@bitfire.at) ...@@ -29,4 +29,5 @@ Email: [play@bitfire.at](mailto:play@bitfire.at)
* Ricki Hirner (initial contributor) * Ricki Hirner (initial contributor)
* David González Verdugo (dgonzalez@owncloud.com) * David González Verdugo (dgonzalez@owncloud.com)
* Matt Jacobsen (https://gitlab.com/mattjacobsen)
buildscript { buildscript {
ext.kotlin_version = '1.3.10' ext.kotlin_version = '1.3.11'
ext.dokka_version = '0.9.17' ext.dokka_version = '0.9.17'
repositories { repositories {
...@@ -61,7 +61,7 @@ dependencies { ...@@ -61,7 +61,7 @@ dependencies {
api "com.squareup.okhttp3:okhttp:$okhttp_version" api "com.squareup.okhttp3:okhttp:$okhttp_version"
androidTestImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version" androidTestImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"
androidTestImplementation 'androidx.test:runner:1.1.0' androidTestImplementation 'androidx.test:runner:1.1.1'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
......
...@@ -350,6 +350,8 @@ open class DavResource @JvmOverloads constructor( ...@@ -350,6 +350,8 @@ open class DavResource @JvmOverloads constructor(
throw when (code) { throw when (code) {
HttpURLConnection.HTTP_UNAUTHORIZED -> HttpURLConnection.HTTP_UNAUTHORIZED ->
if (response != null) UnauthorizedException(response) else UnauthorizedException(message) if (response != null) UnauthorizedException(response) else UnauthorizedException(message)
HttpURLConnection.HTTP_FORBIDDEN ->
if (response != null) ForbiddenException(response) else ForbiddenException(message)
HttpURLConnection.HTTP_NOT_FOUND -> HttpURLConnection.HTTP_NOT_FOUND ->
if (response != null) NotFoundException(response) else NotFoundException(message) if (response != null) NotFoundException(response) else NotFoundException(message)
HttpURLConnection.HTTP_CONFLICT -> HttpURLConnection.HTTP_CONFLICT ->
......
...@@ -37,6 +37,17 @@ class Error( ...@@ -37,6 +37,17 @@ class Error(
return names.map { Error(it) } return names.map { Error(it) }
} }
// some pre-defined errors
val NEED_PRIVILEGES = Error(Property.Name(XmlUtils.NS_WEBDAV, "need-privileges"))
val VALID_SYNC_TOKEN = Error(Property.Name(XmlUtils.NS_WEBDAV, "valid-sync-token"))
} }
override fun equals(other: Any?) =
(other is Error) && other.name == name
override fun hashCode() = name.hashCode()
} }
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package at.bitfire.dav4android.exception
import okhttp3.Response
import java.net.HttpURLConnection
class ForbiddenException: HttpException {
constructor(response: Response): super(response)
constructor(message: String?): super(HttpURLConnection.HTTP_FORBIDDEN, message)
}
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package at.bitfire.dav4android
import org.junit.Assert.assertTrue
import org.junit.Test
class ErrorTest {
@Test
fun testEquals() {
val errors = listOf(Error(Property.Name("DAV:", "valid-sync-token")))
assertTrue(errors.contains(Error.VALID_SYNC_TOKEN))
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment