Skip to content

Commit 9534c0a

Browse files
committed
Tweak retry logic
1 parent cbdc9bd commit 9534c0a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,12 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
354354
localWizardModel.token = token
355355
}
356356
if (!url.isNullOrBlank() && !token.isNullOrBlank()) {
357-
connect()
357+
// It could be jarring to suddenly ask for a token when you are
358+
// just trying to launch the Coder plugin so in this case where
359+
// we are trying to automatically connect to the last deployment
360+
// (or the deployment in the CLI config) do not ask for the
361+
// token again until they explicitly press connect.
362+
connect(false)
358363
}
359364
}
360365
updateWorkspaceActions()
@@ -431,9 +436,10 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
431436
* Existing workspaces will be immediately cleared before attempting to
432437
* connect to the new deployment.
433438
*
434-
* If the token is invalid abort and start over from askTokenAndConnect().
439+
* If the token is invalid abort and start over from askTokenAndConnect()
440+
* unless retry is false.
435441
*/
436-
private fun connect() {
442+
private fun connect(retry: Boolean = true) {
437443
// Clear out old deployment details.
438444
poller?.cancel()
439445
listTableModelOfWorkspaces.items = emptyList()
@@ -469,7 +475,9 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
469475
triggerWorkspacePolling(false)
470476
} catch (e: AuthenticationResponseException) {
471477
logger.error("Token was rejected by $deploymentURL; has your token expired?", e)
472-
askTokenAndConnect(false) // Try again but no more opening browser windows.
478+
if (retry) {
479+
askTokenAndConnect(false) // Try again but no more opening browser windows.
480+
}
473481
} catch (e: SocketTimeoutException) {
474482
logger.error("Unable to connect to $deploymentURL; is it up?", e)
475483
} catch (e: ResponseException) {

0 commit comments

Comments
 (0)