[Vulcan/Hebe] Add server error code handling.

This commit is contained in:
Kuba Szczodrzyński 2021-02-25 22:09:00 +01:00
parent 359432d24d
commit d201c0c448
2 changed files with 30 additions and 2 deletions

View File

@ -171,6 +171,12 @@ const val ERROR_VULCAN_WEB_CERTIFICATE_POST_FAILED = 351
const val ERROR_VULCAN_WEB_GRADUATE_ACCOUNT = 352
const val ERROR_VULCAN_WEB_NO_SCHOOLS = 353
const val ERROR_VULCAN_HEBE_OTHER = 354
const val ERROR_VULCAN_HEBE_SIGNATURE_ERROR = 360
const val ERROR_VULCAN_HEBE_INVALID_PAYLOAD = 361
const val ERROR_VULCAN_HEBE_FIREBASE_ERROR = 362
const val ERROR_VULCAN_HEBE_CERTIFICATE_GONE = 363
const val ERROR_VULCAN_HEBE_SERVER_ERROR = 364
const val ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND = 365
const val ERROR_VULCAN_API_DEPRECATED = 390
const val ERROR_LOGIN_IDZIENNIK_WEB_INVALID_LOGIN = 401

View File

@ -221,9 +221,31 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
}
val status = json.getJsonObject("Status")
if (status?.getInt("Code") != 0) {
val statusCode = status?.getInt("Code") ?: -1
if (statusCode != 0) {
val statusMessage = status?.getString("Message")
val errorCode = when (statusCode) {
-1 -> ERROR_VULCAN_HEBE_SERVER_ERROR
100 -> ERROR_VULCAN_HEBE_SIGNATURE_ERROR
101 -> ERROR_VULCAN_HEBE_INVALID_PAYLOAD
106 -> ERROR_VULCAN_HEBE_FIREBASE_ERROR
108 -> ERROR_VULCAN_HEBE_CERTIFICATE_GONE
200 -> when (true) {
statusMessage?.contains("Class") -> ERROR_LOGIN_VULCAN_NO_PUPILS
statusMessage?.contains("Token") -> ERROR_LOGIN_VULCAN_INVALID_TOKEN
else -> ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND
}
201 -> ERROR_LOGIN_VULCAN_EXPIRED_TOKEN
203 -> when (json.getJsonObject("Envelope").getInt("AvailableRetries")) {
2 -> ERROR_LOGIN_VULCAN_INVALID_PIN_2_REMAINING
1 -> ERROR_LOGIN_VULCAN_INVALID_PIN_1_REMAINING
else -> ERROR_LOGIN_VULCAN_INVALID_PIN_0_REMAINING
}
204 -> ERROR_LOGIN_VULCAN_INVALID_PIN_0_REMAINING
else -> ERROR_VULCAN_HEBE_OTHER
}
data.error(
ApiError(tag, ERROR_VULCAN_HEBE_OTHER)
ApiError(tag, errorCode)
.withResponse(response)
.withApiResponse(json.toString())
)