Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit f3e5453

Browse files
committed
Add the invalid credential error detection through the FailedRequest
1 parent cfd8302 commit f3e5453

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/Nonce.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ sealed interface Nonce {
1919
enum class CookieNonceErrorType {
2020
NOT_AUTHENTICATED,
2121
INVALID_RESPONSE,
22+
INVALID_CREDENTIALS,
2223
CUSTOM_LOGIN_URL,
2324
CUSTOM_ADMIN_URL,
2425
INVALID_NONCE,
25-
CAPTCHA_ERROR,
2626
GENERIC_ERROR,
2727
UNKNOWN
2828
}

fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/NonceRestClient.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@ class NonceRestClient @Inject constructor(
6969
// that it's an authentication issue, otherwise we'll assume it's an invalid response
7070
val errorMessage = extractErrorMessage(response.data.orEmpty())
7171

72+
val errorType = if (hasInvalidCredentialsPattern(response.data.orEmpty())) {
73+
Nonce.CookieNonceErrorType.INVALID_CREDENTIALS
74+
} else if (errorMessage != null) {
75+
Nonce.CookieNonceErrorType.NOT_AUTHENTICATED
76+
} else {
77+
Nonce.CookieNonceErrorType.INVALID_RESPONSE
78+
}
79+
7280
FailedRequest(
7381
timeOfResponse = currentTimeProvider.currentDate().time,
7482
username = username,
75-
type = if (errorMessage != null) Nonce.CookieNonceErrorType.NOT_AUTHENTICATED
76-
else Nonce.CookieNonceErrorType.INVALID_RESPONSE,
83+
type = errorType,
7784
errorMessage = errorMessage
7885
)
7986
}

0 commit comments

Comments
 (0)