Merge branch '4.7.8-staff-build'

This commit is contained in:
Hafiz 2025-07-18 12:52:28 -05:00
commit de1a2b2aa6

View file

@ -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)