Prevent infinite loop on 403 and fix bad url used to load the terms
This commit is contained in:
parent
ff39b22686
commit
0135368328
|
@ -139,7 +139,7 @@ class ReviewTermsViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
Timber.e(failure, "Failed to agree to terms")
|
Timber.e(failure, "Failed to load terms")
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
termsList = Uninitialized
|
termsList = Uninitialized
|
||||||
|
|
|
@ -77,6 +77,9 @@ class WidgetViewModel @AssistedInject constructor(@Assisted val initialState: Wi
|
||||||
private val widgetURLFormatter = widgetService.getWidgetURLFormatter()
|
private val widgetURLFormatter = widgetService.getWidgetURLFormatter()
|
||||||
private val postAPIMediator = widgetService.getWidgetPostAPIMediator()
|
private val postAPIMediator = widgetService.getWidgetPostAPIMediator()
|
||||||
|
|
||||||
|
// Flag to avoid infinite loop
|
||||||
|
private var canRefreshToken = true
|
||||||
|
|
||||||
init {
|
init {
|
||||||
integrationManagerService.addListener(this)
|
integrationManagerService.addListener(this)
|
||||||
if (initialState.widgetKind.isAdmin()) {
|
if (initialState.widgetKind.isAdmin()) {
|
||||||
|
@ -227,7 +230,7 @@ class WidgetViewModel @AssistedInject constructor(@Assisted val initialState: Wi
|
||||||
_viewEvents.post(WidgetViewEvents.LoadFormattedURL(formattedUrl))
|
_viewEvents.post(WidgetViewEvents.LoadFormattedURL(formattedUrl))
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
if (failure is WidgetManagementFailure.TermsNotSignedException) {
|
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)) }
|
setState { copy(formattedURL = Fail(failure)) }
|
||||||
}
|
}
|
||||||
|
@ -251,7 +254,8 @@ class WidgetViewModel @AssistedInject constructor(@Assisted val initialState: Wi
|
||||||
}
|
}
|
||||||
if (action.isHttpError) {
|
if (action.isHttpError) {
|
||||||
// In case of 403, try to refresh the scalar token
|
// 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)
|
loadFormattedUrl(true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue