[APIv2] Librus/Synergia request: error handling. Mobidziennik: fix login error code.

This commit is contained in:
Kuba Szczodrzyński 2019-10-27 15:30:24 +01:00
parent 28e0f3487c
commit 46dd543b48
4 changed files with 22 additions and 10 deletions

View File

@ -81,7 +81,7 @@ const val ERROR_LOGIN_LIBRUS_SYNERGIA_NO_SESSION_ID = 154
const val ERROR_LIBRUS_MESSAGES_ACCESS_DENIED = 155
const val ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED = 156
const val ERROR_LOGIN_LIBRUS_MESSAGES_NO_SESSION_ID = 157
const val ERROR_LIBRUS_PORTAL_TOKEN_EXPIRED = 158
const val ERROR_LIBRUS_PORTAL_ACCESS_DENIED = 158
const val ERROR_LIBRUS_PORTAL_API_DISABLED = 159
const val ERROR_LIBRUS_PORTAL_SYNERGIA_DISCONNECTED = 160
const val ERROR_LIBRUS_PORTAL_OTHER = 161
@ -97,6 +97,8 @@ const val ERROR_LOGIN_LIBRUS_PORTAL_UNSUPPORTED_GRANT = 170
const val ERROR_LOGIN_LIBRUS_PORTAL_INVALID_CLIENT_ID = 171
const val ERROR_LOGIN_LIBRUS_PORTAL_REFRESH_INVALID = 172
const val ERROR_LOGIN_LIBRUS_PORTAL_REFRESH_REVOKED = 173
const val ERROR_LIBRUS_SYNERGIA_OTHER = 174
const val ERROR_LIBRUS_SYNERGIA_MAINTENANCE = 175
const val ERROR_LOGIN_MOBIDZIENNIK_WEB_INVALID_LOGIN = 201
const val ERROR_LOGIN_MOBIDZIENNIK_WEB_OLD_PASSWORD = 202
@ -110,6 +112,7 @@ const val ERROR_MOBIDZIENNIK_WEB_NO_SESSION_KEY = 212
const val ERROR_MOBIDZIENNIK_WEB_NO_SESSION_VALUE = 212
const val ERROR_MOBIDZIENNIK_WEB_NO_SERVER_ID = 213
const val ERROR_MOBIDZIENNIK_WEB_INVALID_RESPONSE = 214
const val ERROR_LOGIN_MOBIDZIENNIK_WEB_NO_SESSION_ID = 215
const val ERROR_LOGIN_VULCAN_INVALID_SYMBOL = 301
const val ERROR_LOGIN_VULCAN_INVALID_TOKEN = 302

View File

@ -41,7 +41,7 @@ open class LibrusPortal(open val data: DataLibrus) {
error?.let { code ->
when (code) {
"requires_an_action" -> ERROR_LIBRUS_PORTAL_SYNERGIA_DISCONNECTED
"Access token is invalid" -> ERROR_LIBRUS_PORTAL_TOKEN_EXPIRED
"Access token is invalid" -> ERROR_LIBRUS_PORTAL_ACCESS_DENIED
"ApiDisabled" -> ERROR_LIBRUS_PORTAL_API_DISABLED
"Account not found" -> ERROR_LIBRUS_PORTAL_SYNERGIA_NOT_FOUND
else -> ERROR_LIBRUS_PORTAL_OTHER

View File

@ -7,9 +7,6 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data
import im.wangchao.mhttp.Request
import im.wangchao.mhttp.Response
import im.wangchao.mhttp.callback.TextCallbackHandler
import okhttp3.Cookie
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import pl.szczodrzynski.edziennik.api.v2.*
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
@ -38,7 +35,19 @@ open class LibrusSynergia(open val data: DataLibrus) {
return
}
// TODO: Error handling
if (!text.contains("jesteś zalogowany")) {
when {
text.contains("stop.png") -> ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED
text.contains("Przerwa techniczna") -> ERROR_LIBRUS_SYNERGIA_MAINTENANCE
else -> ERROR_LIBRUS_SYNERGIA_OTHER
}.let { errorCode ->
data.error(ApiError(tag, errorCode)
.withResponse(response)
.withApiResponse(text))
return
}
}
try {
onSuccess(text)
@ -57,13 +66,13 @@ open class LibrusSynergia(open val data: DataLibrus) {
}
}
data.app.cookieJar.saveFromResponse(null, listOf(
/*data.app.cookieJar.saveFromResponse(null, listOf(
Cookie.Builder()
.name("DZIENNIKSID")
.value(data.synergiaSessionId!!)
.domain("synergia.librus.pl")
.secure().httpOnly().build()
))
))*/
Request.builder()
.url("$LIBRUS_SYNERGIA_URL/$endpoint")

View File

@ -62,7 +62,7 @@ class MobidziennikLoginWeb(val data: DataMobidziennik, val onSuccess: () -> Unit
val sessionKey = cookie?.name()
val sessionId = cookie?.value()
if (sessionId == null) {
data.error(ApiError(TAG, ERROR_LOGIN_LIBRUS_SYNERGIA_NO_SESSION_ID)
data.error(ApiError(TAG, ERROR_LOGIN_MOBIDZIENNIK_WEB_NO_SESSION_ID)
.withResponse(response)
.withApiResponse(text))
return
@ -85,7 +85,7 @@ class MobidziennikLoginWeb(val data: DataMobidziennik, val onSuccess: () -> Unit
Request.builder()
.url("https://${data.loginServerName}.mobidziennik.pl/api/")
.userAgent(System.getProperty("http.agent"))
.userAgent(MOBIDZIENNIK_USER_AGENT)
.contentType("application/x-www-form-urlencoded; charset=UTF-8")
.addParameter("wersja", "20")
.addParameter("ip", data.app.deviceId)