mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Prevent infinite loop on 403 and fix bad url used to load the terms
This commit is contained in:
parent
ff39b22686
commit
0135368328
2 changed files with 7 additions and 3 deletions
|
@ -139,7 +139,7 @@ class ReviewTermsViewModel @AssistedInject constructor(
|
|||
)
|
||||
}
|
||||
} catch (failure: Throwable) {
|
||||
Timber.e(failure, "Failed to agree to terms")
|
||||
Timber.e(failure, "Failed to load terms")
|
||||
setState {
|
||||
copy(
|
||||
termsList = Uninitialized
|
||||
|
|
|
@ -77,6 +77,9 @@ class WidgetViewModel @AssistedInject constructor(@Assisted val initialState: Wi
|
|||
private val widgetURLFormatter = widgetService.getWidgetURLFormatter()
|
||||
private val postAPIMediator = widgetService.getWidgetPostAPIMediator()
|
||||
|
||||
// Flag to avoid infinite loop
|
||||
private var canRefreshToken = true
|
||||
|
||||
init {
|
||||
integrationManagerService.addListener(this)
|
||||
if (initialState.widgetKind.isAdmin()) {
|
||||
|
@ -227,7 +230,7 @@ class WidgetViewModel @AssistedInject constructor(@Assisted val initialState: Wi
|
|||
_viewEvents.post(WidgetViewEvents.LoadFormattedURL(formattedUrl))
|
||||
} catch (failure: Throwable) {
|
||||
if (failure is WidgetManagementFailure.TermsNotSignedException) {
|
||||
_viewEvents.post(WidgetViewEvents.DisplayTerms(failure.baseUrl, failure.token))
|
||||
_viewEvents.post(WidgetViewEvents.DisplayTerms(initialState.baseUrl, failure.token))
|
||||
}
|
||||
setState { copy(formattedURL = Fail(failure)) }
|
||||
}
|
||||
|
@ -251,7 +254,8 @@ class WidgetViewModel @AssistedInject constructor(@Assisted val initialState: Wi
|
|||
}
|
||||
if (action.isHttpError) {
|
||||
// In case of 403, try to refresh the scalar token
|
||||
if (it.formattedURL is Success && action.errorCode == HttpsURLConnection.HTTP_FORBIDDEN) {
|
||||
if (it.formattedURL is Success && action.errorCode == HttpsURLConnection.HTTP_FORBIDDEN && canRefreshToken) {
|
||||
canRefreshToken = false
|
||||
loadFormattedUrl(true)
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue