@@ -2,7 +2,6 @@ package com.coder.toolbox
22
33import com.coder.toolbox.cli.CoderCLIManager
44import com.coder.toolbox.sdk.CoderRestClient
5- import com.coder.toolbox.sdk.ex.APIResponseException
65import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
76import com.coder.toolbox.util.CoderProtocolHandler
87import com.coder.toolbox.util.DialogUi
@@ -30,7 +29,6 @@ import kotlinx.coroutines.isActive
3029import kotlinx.coroutines.launch
3130import kotlinx.coroutines.selects.onTimeout
3231import kotlinx.coroutines.selects.select
33- import java.net.SocketTimeoutException
3432import java.net.URI
3533import kotlin.coroutines.cancellation.CancellationException
3634import kotlin.time.Duration.Companion.seconds
@@ -58,11 +56,6 @@ class CoderRemoteProvider(
5856 // The REST client, if we are signed in
5957 private var client: CoderRestClient ? = null
6058
61- // If we have an error in the polling we store it here before going back to
62- // sign-in page, so we can display it there. This is mainly because there
63- // does not seem to be a mechanism to show errors on the environment list.
64- private var errorBuffer = mutableListOf<Throwable >()
65-
6659 // On the first load, automatically log in if we can.
6760 private var firstRun = true
6861 private val isInitialized: MutableStateFlow <Boolean > = MutableStateFlow (false )
@@ -135,29 +128,17 @@ class CoderRemoteProvider(
135128 } catch (_: CancellationException ) {
136129 context.logger.debug(" ${client.url} polling loop canceled" )
137130 break
138- } catch (ex: SocketTimeoutException ) {
131+ } catch (ex: Exception ) {
139132 val elapsed = lastPollTime.elapsedNow()
140133 if (elapsed > POLL_INTERVAL * 2 ) {
141134 context.logger.info(" wake-up from an OS sleep was detected, going to re-initialize the http client..." )
142135 client.setupSession()
143136 } else {
144- context.logger.error(ex, " workspace polling error encountered" )
145- errorBuffer.add(ex )
146- logout ()
137+ context.logger.error(ex, " workspace polling error encountered, trying to auto-login " )
138+ close( )
139+ goToEnvironmentsPage ()
147140 break
148141 }
149- } catch (ex: APIResponseException ) {
150- context.logger.error(ex, " error in contacting ${client.url} while polling the available workspaces" )
151- errorBuffer.add(ex)
152- logout()
153- goToEnvironmentsPage()
154- break
155- } catch (ex: Exception ) {
156- context.logger.error(ex, " workspace polling error encountered" )
157- errorBuffer.add(ex)
158- logout()
159- goToEnvironmentsPage()
160- break
161142 }
162143
163144 // TODO: Listening on a web socket might be better?
@@ -306,6 +287,7 @@ class CoderRemoteProvider(
306287 override fun getOverrideUiPage (): UiPage ? {
307288 // Show sign in page if we have not configured the client yet.
308289 if (client == null ) {
290+ val errorBuffer = mutableListOf<Throwable >()
309291 // When coming back to the application, authenticate immediately.
310292 val autologin = shouldDoAutoLogin()
311293 context.secrets.lastToken.let { lastToken ->
@@ -329,7 +311,6 @@ class CoderRemoteProvider(
329311 authWizard.notify(" Error encountered" , it)
330312 }
331313 // and now reset the errors, otherwise we show it every time on the screen
332- errorBuffer.clear()
333314 return authWizard
334315 }
335316 return null
@@ -344,7 +325,6 @@ class CoderRemoteProvider(
344325 // Currently we always remember, but this could be made an option.
345326 context.secrets.rememberMe = true
346327 this .client = client
347- errorBuffer.clear()
348328 pollJob?.cancel()
349329 pollJob = poll(client, cli)
350330 goToEnvironmentsPage()
0 commit comments