From 8c099bc137d27bee4f03e7f448b3a7ed37a498ca Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Fri, 25 Oct 2019 00:24:55 +0200 Subject: [PATCH] [APIv2/Librus] Add handling denied access in messages --- .../edziennik/api/v2/librus/data/LibrusMessages.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusMessages.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusMessages.kt index c31ac8e5..e964e0b4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusMessages.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusMessages.kt @@ -15,6 +15,7 @@ import org.redundent.kotlin.xml.xml import pl.szczodrzynski.edziennik.api.v2.* import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus import pl.szczodrzynski.edziennik.api.v2.models.ApiError +import pl.szczodrzynski.edziennik.get import pl.szczodrzynski.edziennik.utils.Utils.d open class LibrusMessages(open val data: DataLibrus) { @@ -41,7 +42,15 @@ open class LibrusMessages(open val data: DataLibrus) { return } - // TODO: Error handling + // TODO: Finish error handling + + if ("error" in text) { + when ("(.*)".toRegex().find(text)?.get(1)) { + "eAccessDeny" -> data.error(ApiError(tag, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED) + .withResponse(response) + .withApiResponse(text)) + } + } try { val doc = Jsoup.parse(text, "", Parser.xmlParser())