mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 11:46:32 +00:00
Merge branch '4.7.8-staff-build'
This commit is contained in:
commit
de1a2b2aa6
1 changed files with 13 additions and 16 deletions
|
|
@ -161,23 +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)
|
||||
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)
|
||||
|
|
@ -310,6 +303,10 @@ class ApiClientImpl(
|
|||
return
|
||||
}
|
||||
|
||||
if (res.displayMessage.isNotEmpty() && res.displayMessage.contains("Missing authentication headers", ignoreCase = true)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (status in 400..499) {
|
||||
if (res.displayMessage.isNotEmpty()) {
|
||||
showConnectionProblemDialog("", res.displayMessage, isUserInputCall)
|
||||
|
|
|
|||
Loading…
Reference in a new issue