From 9bac239f779a6022d2667020ce7080403b70c4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sun, 15 Mar 2020 20:15:10 +0100 Subject: [PATCH] [API/Librus] Add handling message not found error. Fix for duplicated errors and exceptions. --- .../edziennik/data/api/Errors.kt | 1 + .../edziennik/librus/data/LibrusMessages.kt | 42 ++++++++++++------- app/src/main/res/values/errors.xml | 2 + 3 files changed, 31 insertions(+), 14 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 462fa7a4..5f437ca6 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 @@ -124,6 +124,7 @@ const val ERROR_LIBRUS_PORTAL_MAINTENANCE = 182 const val ERROR_LIBRUS_API_NOTICEBOARD_PROBLEM = 183 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_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/LibrusMessages.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusMessages.kt index febdab75..aaff8648 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusMessages.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusMessages.kt @@ -55,13 +55,20 @@ open class LibrusMessages(open val data: DataLibrus, open val lastSync: Long?) { } when { - text.contains("Niepoprawny login i/lub hasło.") -> data.error(TAG, ERROR_LOGIN_LIBRUS_MESSAGES_INVALID_LOGIN, response, text) - text.contains("stop.png") -> data.error(TAG, ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED, response, text) - text.contains("eAccessDeny") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text) - text.contains("OffLine") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_MAINTENANCE, response, text) - text.contains("error") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ERROR, response, text) - text.contains("eVarWhitThisNameNotExists") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text) - text.contains("") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_OTHER, response, text) + text.contains("Niepoprawny login i/lub hasło.") -> ERROR_LOGIN_LIBRUS_MESSAGES_INVALID_LOGIN + text.contains("Nie odnaleziono wiadomości.") -> ERROR_LIBRUS_MESSAGES_NOT_FOUND + text.contains("stop.png") -> ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED + text.contains("eAccessDeny") -> ERROR_LIBRUS_MESSAGES_ACCESS_DENIED + text.contains("OffLine") -> ERROR_LIBRUS_MESSAGES_MAINTENANCE + text.contains("error") -> ERROR_LIBRUS_MESSAGES_ERROR + text.contains("eVarWhitThisNameNotExists") -> ERROR_LIBRUS_MESSAGES_ACCESS_DENIED + text.contains("") -> ERROR_LIBRUS_MESSAGES_OTHER + else -> null + }?.let { errorCode -> + data.error(ApiError(tag, errorCode) + .withApiResponse(text) + .withResponse(response)) + return } try { @@ -139,13 +146,20 @@ open class LibrusMessages(open val data: DataLibrus, open val lastSync: Long?) { } when { - text.contains("Niepoprawny login i/lub hasło.") -> data.error(TAG, ERROR_LOGIN_LIBRUS_MESSAGES_INVALID_LOGIN, response, text) - text.contains("stop.png") -> data.error(TAG, ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED, response, text) - text.contains("eAccessDeny") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text) - text.contains("OffLine") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_MAINTENANCE, response, text) - text.contains("error") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ERROR, response, text) - text.contains("eVarWhitThisNameNotExists") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text) - text.contains("") -> data.error(TAG, ERROR_LIBRUS_MESSAGES_OTHER, response, text) + text.contains("Niepoprawny login i/lub hasło.") -> ERROR_LOGIN_LIBRUS_MESSAGES_INVALID_LOGIN + text.contains("Nie odnaleziono wiadomości.") -> ERROR_LIBRUS_MESSAGES_NOT_FOUND + text.contains("stop.png") -> ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED + text.contains("eAccessDeny") -> ERROR_LIBRUS_MESSAGES_ACCESS_DENIED + text.contains("OffLine") -> ERROR_LIBRUS_MESSAGES_MAINTENANCE + text.contains("error") -> ERROR_LIBRUS_MESSAGES_ERROR + text.contains("eVarWhitThisNameNotExists") -> ERROR_LIBRUS_MESSAGES_ACCESS_DENIED + text.contains("") -> ERROR_LIBRUS_MESSAGES_OTHER + else -> null + }?.let { errorCode -> + data.error(ApiError(tag, errorCode) + .withApiResponse(text) + .withResponse(response)) + return } try { diff --git a/app/src/main/res/values/errors.xml b/app/src/main/res/values/errors.xml index 903c87bf..1ac75414 100644 --- a/app/src/main/res/values/errors.xml +++ b/app/src/main/res/values/errors.xml @@ -96,6 +96,7 @@ ERROR_LIBRUS_API_NOTICEBOARD_PROBLEM ERROR_LOGIN_LIBRUS_PORTAL_CSRF_EXPIRED ERROR_LIBRUS_API_DEVICE_REGISTERED + ERROR_LIBRUS_MESSAGES_NOT_FOUND ERROR_LOGIN_MOBIDZIENNIK_WEB_INVALID_LOGIN ERROR_LOGIN_MOBIDZIENNIK_WEB_OLD_PASSWORD @@ -268,6 +269,7 @@ Wystąpił problem z tablicą ogłoszeń Librus: Sesja logowania wygasła. Zaloguj się ponownie. Urządzenie jest już zarejestrowane + Nie znaleziono wiadomości. Mogła zostać usunięta. Nieprawidłowy login lub hasło Podano stare hasło