From ea4919a25d8c66cc5b5699f77970d4b6440ded33 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Sat, 4 Apr 2020 22:23:31 +0200 Subject: [PATCH] [API/Librus] Add handling missing attachment error. --- .../edziennik/data/api/Errors.kt | 1 + .../LibrusSandboxDownloadAttachment.kt | 23 ++++++++++++------- app/src/main/res/values/errors.xml | 2 ++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt index 1d86abf6..989a279c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt @@ -126,6 +126,7 @@ const val ERROR_LOGIN_LIBRUS_PORTAL_CSRF_EXPIRED = 184 const val ERROR_LIBRUS_API_DEVICE_REGISTERED = 185 const val ERROR_LIBRUS_MESSAGES_NOT_FOUND = 186 const val ERROR_LOGIN_LIBRUS_API_INVALID_REQUEST = 187 +const val ERROR_LIBRUS_MESSAGES_ATTACHMENT_NOT_FOUND = 188 const val ERROR_LOGIN_MOBIDZIENNIK_WEB_INVALID_LOGIN = 201 const val ERROR_LOGIN_MOBIDZIENNIK_WEB_OLD_PASSWORD = 202 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusSandboxDownloadAttachment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusSandboxDownloadAttachment.kt index ff3196ea..c6131bb2 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusSandboxDownloadAttachment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/messages/LibrusSandboxDownloadAttachment.kt @@ -34,15 +34,22 @@ class LibrusSandboxDownloadAttachment(override val data: DataLibrus, init { val keyMatcher = Regexes.LIBRUS_ATTACHMENT_KEY.find(downloadLink) - if (keyMatcher != null) { - getAttachmentCheckKeyTries = 0 - - val attachmentKey = keyMatcher[1] - getAttachmentCheckKey(attachmentKey) { - downloadAttachment("${LIBRUS_SANDBOX_URL}CSDownload&singleUseKey=$attachmentKey", method = POST) + when { + downloadLink.contains("CSDownloadFailed") -> { + data.error(ApiError(TAG, ERROR_LIBRUS_MESSAGES_ATTACHMENT_NOT_FOUND)) + onSuccess() + } + keyMatcher != null -> { + getAttachmentCheckKeyTries = 0 + + val attachmentKey = keyMatcher[1] + getAttachmentCheckKey(attachmentKey) { + downloadAttachment("${LIBRUS_SANDBOX_URL}CSDownload&singleUseKey=$attachmentKey", method = POST) + } + } + else -> { + downloadAttachment("$downloadLink/get", method = GET) } - } else { - downloadAttachment("$downloadLink/get", method = GET) } } diff --git a/app/src/main/res/values/errors.xml b/app/src/main/res/values/errors.xml index b0eb94dd..8d14b725 100644 --- a/app/src/main/res/values/errors.xml +++ b/app/src/main/res/values/errors.xml @@ -98,6 +98,7 @@ ERROR_LIBRUS_API_DEVICE_REGISTERED ERROR_LIBRUS_MESSAGES_NOT_FOUND ERROR_LOGIN_LIBRUS_API_INVALID_REQUEST + ERROR_LIBRUS_MESSAGES_ATTACHMENT_NOT_FOUND ERROR_LOGIN_MOBIDZIENNIK_WEB_INVALID_LOGIN ERROR_LOGIN_MOBIDZIENNIK_WEB_OLD_PASSWORD @@ -273,6 +274,7 @@ Urządzenie jest już zarejestrowane Nie znaleziono wiadomości. Mogła zostać usunięta. Nieprawidłowe dane dostępu. Sprawdź poprawność wprowadzonych danych. + Nie znaleziono załącznika. Mógł zostać usunięty. Nieprawidłowy login lub hasło Podano stare hasło