Skip to content

Commit

Permalink
Fix showing errors on the login screen
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharee committed Aug 10, 2024
1 parent dee9847 commit bbd4fab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ sealed class Endpoint(open val url: String) {

data class CommonApiEndpoint(override val url: String) : Endpoint(url) {
override fun createFullUrl(): String {
return "http://${SettingsModel.gatewayIp.value}/${Endpoints.CommonApiV1.BASE_URL}/$url"
val address = SettingsModel.gatewayIp.value
val port = if (address.contains(Regex(":\\d+.*$"))) "" else ":8080"
return "http://$address$port/${Endpoints.CommonApiV1.BASE_URL}/$url"
}
}

Expand All @@ -16,6 +18,7 @@ sealed class Endpoint(open val url: String) {
}
}

@Suppress("unused")
sealed class Endpoints {
data object CommonApiV1 : Endpoints() {
const val BASE_URL = "TMI/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ fun LoginPage(

var actualClient = client

error = null
if (actualClient == null) {
actualClient = GlobalModel.updateClient()
}
error = null
focusManager.clearFocus()
isBlocking = true
actualClient?.getMainData(true)
Expand Down
13 changes: 10 additions & 3 deletions common/src/commonMain/kotlin/dev/zwander/common/util/HTTPClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ interface HTTPClient {
showError: Boolean = true,
reportError: Boolean = true,
retryForLive: Boolean = false,
isLogin: Boolean = false,
maxRetries: Int = 20,
retryOnCodes: IntArray = intArrayOf(408),
methodBlock: suspend HttpClient.() -> HttpResponse,
Expand Down Expand Up @@ -606,14 +607,20 @@ interface HTTPClient {
if (retryForLive && attempt < maxRetries) {
delay(2000)
tryRequest(attempt + 1)
} else {
} else if (!isLogin) {
if (!waitForLive()) {
if (showError) {
GlobalModel.updateHttpError(e)
} else if (reportError) {
CrossPlatformBugsnag.notify(e)
}
}
} else {
if (showError) {
GlobalModel.updateHttpError(e)
} else if (reportError) {
CrossPlatformBugsnag.notify(e)
}
}
} catch (e: Exception) {
Exception(e).printStackTrace()
Expand Down Expand Up @@ -667,7 +674,7 @@ private object NokiaClient : HTTPClient {

override suspend fun logIn(username: String, password: String, rememberCredentials: Boolean) {
withLoader(true) {
val response = unauthedClient.handleCatch {
val response = unauthedClient.handleCatch(isLogin = true) {
submitForm(
url = Endpoints.NokiaApi.login.createFullUrl(),
formParameters = parameters {
Expand Down Expand Up @@ -1013,7 +1020,7 @@ private object UnifiedClient : HTTPClient {

override suspend fun logIn(username: String, password: String, rememberCredentials: Boolean) {
withLoader(true) {
val response = unauthedClient.handleCatch {
val response = unauthedClient.handleCatch(isLogin = true) {
post(Endpoints.CommonApiV1.auth.createFullUrl()) {
contentType(ContentType.parse("application/json"))
accept(ContentType.parse("application/json"))
Expand Down

0 comments on commit bbd4fab

Please # to comment.