mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 11:46:32 +00:00
add language-agnostic invalid_credentials error handling
This commit is contained in:
parent
d1f7012540
commit
1411d49107
1 changed files with 9 additions and 17 deletions
|
|
@ -161,24 +161,16 @@ class ApiClientImpl(
|
|||
val path = response.request.url.encodedPath
|
||||
|
||||
if (!path.contains("/user/auth/update-password") && !path.contains("group-plans")) {
|
||||
val bodyStr = try {
|
||||
response.peekBody(1024).string()
|
||||
} catch (_: Exception) {
|
||||
""
|
||||
}
|
||||
val bodyStr = runCatching { response.peekBody(1024).string() }.getOrDefault("")
|
||||
|
||||
val (errField, msgField) = try {
|
||||
val obj = JSONObject(bodyStr)
|
||||
obj.optString("error", "") to obj.optString("message", "")
|
||||
} catch (_: Exception) {
|
||||
"" to ""
|
||||
}
|
||||
|
||||
val shouldLogout = errField.equals("missingAuthHeaders", ignoreCase = true)
|
||||
|| errField.equals("invalidCredentials", ignoreCase = true)
|
||||
|| msgField.contains("invalidCredentials", ignoreCase = true)
|
||||
|| msgField.contains("Missing authentication headers", ignoreCase = true)
|
||||
|| msgField.contains("There is no account that uses those credentials", ignoreCase = true)
|
||||
val (errField, _) = runCatching {
|
||||
JSONObject(bodyStr).let {
|
||||
it.optString("error", "") to it.optString("message", "")
|
||||
}
|
||||
}.getOrDefault("" to "")
|
||||
|
||||
// logout if language agnostic "invalid_credentials" error is returned
|
||||
val shouldLogout = errField.equals("invalid_credentials", ignoreCase = true)
|
||||
|
||||
if (shouldLogout) {
|
||||
HabiticaBaseApplication.logout(context)
|
||||
|
|
|
|||
Loading…
Reference in a new issue