Этап 1: единый OkHttpClient ч.2 — 401 централизован через interceptor
- UnauthorizedInterceptor (401→UnauthorizedException) в NetworkFactory, флаг throwOnUnauthorized (по умолчанию true). - Удалены 75 ручных проверок if(code==401) throw в 16 репозиториях. - AuthVerifier (login-верификация) исключён: throwOnUnauthorized=false — 401 = 'неверный пароль' со своим сообщением, не session-expired. - Побочно: 401 теперь ловится единообразно ВЕЗДЕ (включая пути, что раньше забывали проверку). - +3 MockWebServer-теста (401 бросает; 200/403 проходят) — всего 18 тестов. Проверено: 18 тестов зелёные + assembleRelease BUILD SUCCESSFUL, APK 53 МБ.
This commit is contained in:
@@ -59,7 +59,6 @@ object TalkAttachmentUploader {
|
||||
.header("Accept", "application/json")
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful || response.body == null) return DEFAULT_ATTACHMENT_FOLDER
|
||||
val data = JSONObject(response.body!!.string())
|
||||
.optJSONObject("ocs")
|
||||
@@ -110,7 +109,6 @@ object TalkAttachmentUploader {
|
||||
val url = davFileUrl(session.serverUrl, davUserId, remotePath.trim('/'))
|
||||
val request = Request.Builder().url(url).head().build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
return response.isSuccessful
|
||||
}
|
||||
}
|
||||
@@ -136,7 +134,6 @@ object TalkAttachmentUploader {
|
||||
.method("MKCOL", ByteArray(0).toRequestBody(null))
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
// 405 = already exists
|
||||
}
|
||||
}
|
||||
@@ -156,7 +153,6 @@ object TalkAttachmentUploader {
|
||||
.put(bytes.toRequestBody(mediaType))
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful) {
|
||||
error("Не удалось загрузить файл: HTTP ${response.code}")
|
||||
}
|
||||
@@ -190,7 +186,6 @@ object TalkAttachmentUploader {
|
||||
.post(body)
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful) {
|
||||
error("Не удалось отправить вложение в чат: HTTP ${response.code}")
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ class TalkRepository {
|
||||
.post(payload.toRequestBody("application/json; charset=utf-8".toMediaType()))
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful) {
|
||||
error("Talk read marker failed: HTTP ${response.code}")
|
||||
}
|
||||
@@ -166,7 +165,6 @@ class TalkRepository {
|
||||
builder.delete()
|
||||
}
|
||||
client.newCall(builder.build()).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful) error("Talk favorite failed: HTTP ${response.code}")
|
||||
}
|
||||
}
|
||||
@@ -181,7 +179,6 @@ class TalkRepository {
|
||||
.delete()
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful) error("Talk mark unread failed: HTTP ${response.code}")
|
||||
}
|
||||
}
|
||||
@@ -215,7 +212,6 @@ class TalkRepository {
|
||||
.post(payload.toString().toRequestBody("application/json; charset=utf-8".toMediaType()))
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (response.code != 201 && !response.isSuccessful) {
|
||||
error("Talk send failed: HTTP ${response.code}")
|
||||
}
|
||||
@@ -270,7 +266,6 @@ class TalkRepository {
|
||||
"DELETE" -> builder.delete()
|
||||
}
|
||||
client.newCall(builder.build()).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful) error("Talk request failed: HTTP ${response.code}")
|
||||
}
|
||||
}
|
||||
@@ -288,7 +283,6 @@ class TalkRepository {
|
||||
.put(body)
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful) error("Talk edit failed: HTTP ${response.code}")
|
||||
}
|
||||
}
|
||||
@@ -323,7 +317,6 @@ class TalkRepository {
|
||||
.delete()
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful) error("Talk delete failed: HTTP ${response.code}")
|
||||
}
|
||||
}
|
||||
@@ -351,7 +344,6 @@ class TalkRepository {
|
||||
.post(payload.toRequestBody("application/json; charset=utf-8".toMediaType()))
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful || response.body == null) {
|
||||
error("Talk request failed: HTTP ${response.code}")
|
||||
}
|
||||
@@ -371,7 +363,6 @@ class TalkRepository {
|
||||
.header("Accept", "application/json")
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
if (response.code == 401) throw UnauthorizedException()
|
||||
if (!response.isSuccessful || response.body == null) {
|
||||
error("Talk request failed: HTTP ${response.code}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user