You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: stream-android-core/src/main/java/io/getstream/android/core/api/model/config/StreamClientSerializationConfig.kt
Copy file name to clipboardExpand all lines: stream-android-core/src/main/java/io/getstream/android/core/internal/http/interceptor/StreamAuthInterceptor.kt
+18-22Lines changed: 18 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -67,25 +67,25 @@ internal class StreamAuthInterceptor(
67
67
val original = chain.request()
68
68
val authed = original.withAuthHeaders(authType, token.rawValue)
69
69
70
-
valfirstResponse= chain.proceed(authed)
71
-
if (firstResponse.isSuccessful) {
72
-
returnfirstResponse
70
+
valfirst= chain.proceed(authed)
71
+
if (first.isSuccessful) {
72
+
returnfirst
73
73
}
74
74
75
-
val errorBody = firstResponse.peekBody(PEEK_ERROR_BYTES_MAX).string()
76
-
val parsed = jsonParser.fromJson(errorBody, StreamEndpointErrorData::class.java)
75
+
// Peek only; do NOT consume
76
+
val peeked = first.peekBody(PEEK_ERROR_BYTES_MAX).string()
77
+
val parsed = jsonParser.fromJson(peeked, StreamEndpointErrorData::class.java)
77
78
78
-
// Guard against infinite loops: retry at most once per request.
79
79
val alreadyRetried = original.header(HEADER_RETRIED_ON_AUTH) =="present"
80
80
81
81
if (parsed.isSuccess) {
82
82
val error = parsed.getOrEndpointException("Failed to parse error body.")
83
-
if (!alreadyRetried && isTokenInvalidErrorCode(error.code)) {
84
-
//Refresh and retry once.
85
-
firstResponse.close()
86
-
tokenManager
87
-
.invalidate()
88
-
.getOrEndpointException(message ="Failed to invalidate token")
83
+
84
+
//Only handle token errors here
85
+
if (isTokenInvalidErrorCode(error.code) &&!alreadyRetried) {
86
+
// refresh & retry once
87
+
first.close()
88
+
tokenManager.invalidate().getOrEndpointException("Failed to invalidate token")
89
89
val refreshed =
90
90
runBlocking { tokenManager.refresh() }
91
91
.getOrEndpointException("Failed to refresh token")
@@ -97,19 +97,15 @@ internal class StreamAuthInterceptor(
97
97
.header(HEADER_RETRIED_ON_AUTH, "present")
98
98
.build()
99
99
100
-
return chain.proceed(retried)
100
+
return chain.proceed(retried)// pass result (ok or error) downstream
101
101
}
102
102
103
-
// Non-token error or we already retried: surface a structured exception.
Copy file name to clipboardExpand all lines: stream-android-core/src/test/java/io/getstream/android/core/internal/http/interceptor/StreamAuthInterceptorTest.kt
0 commit comments