From 37d073ce7754a224aecea88bbbf29f3b83b7c238 Mon Sep 17 00:00:00 2001 From: tateisu Date: Thu, 13 May 2021 22:03:29 +0900 Subject: [PATCH] fix #156, Subway Tooter requests grant type client_credentials when trying to connect to Friendica --- .../juggler/subwaytooter/api/TootApiClient.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/jp/juggler/subwaytooter/api/TootApiClient.kt b/app/src/main/java/jp/juggler/subwaytooter/api/TootApiClient.kt index 032e00dd..c3bf90d8 100644 --- a/app/src/main/java/jp/juggler/subwaytooter/api/TootApiClient.kt +++ b/app/src/main/java/jp/juggler/subwaytooter/api/TootApiClient.kt @@ -138,13 +138,13 @@ class TootApiClient( fun simplifyErrorHtml( response: Response, - caption:String = "?", - bodyString:String =response.body?.string() ?: "", + caption: String = "?", + bodyString: String = response.body?.string() ?: "", jsonErrorParser: (json: JsonObject) -> String? = DEFAULT_JSON_ERROR_PARSER ) = TootApiResult( response = response, caption = caption, - ).simplifyErrorHtml( bodyString,jsonErrorParser) + ).simplifyErrorHtml(bodyString, jsonErrorParser) } // 認証に関する設定を保存する @@ -965,10 +965,18 @@ class TootApiClient( var client_credential = client_info.string(KEY_CLIENT_CREDENTIAL) if (client_credential?.isEmpty() != false) { val resultSub = getClientCredential(client_info) - client_credential = resultSub?.string - if (client_credential?.isEmpty() != false) return resultSub - - client_info[KEY_CLIENT_CREDENTIAL] = client_credential + if (resultSub?.response?.code == 422) { + // https://github.com/tateisu/SubwayTooter/issues/156 + // some servers not support to get client_credentials. + // just ignore error and skip. + } else if (resultSub == null || resultSub.error != null) { + return resultSub + } else { + resultSub.string?.notEmpty()?.let { + client_credential = it + client_info[KEY_CLIENT_CREDENTIAL] = it + } + } } try {