@@ -18,6 +18,7 @@ import com.coder.gateway.sdk.TemplateIconDownloader
1818import com.coder.gateway.sdk.ex.AuthenticationResponseException
1919import com.coder.gateway.sdk.ex.TemplateResponseException
2020import com.coder.gateway.sdk.ex.WorkspaceResponseException
21+ import com.coder.gateway.sdk.isCancellation
2122import com.coder.gateway.sdk.toURL
2223import com.coder.gateway.sdk.v2.models.WorkspaceStatus
2324import com.coder.gateway.sdk.v2.models.toAgentModels
@@ -423,12 +424,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
423424 tableOfWorkspaces.listTableModel.items = emptyList()
424425
425426 // Authenticate and load in a background process with progress.
426- // TODO: Make this cancelable.
427- return LifetimeDefinition ().launchUnderBackgroundProgress(
428- CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.cli.downloader.dialog.title" ),
429- canBeCancelled = false ,
430- isIndeterminate = true
431- ) {
427+ return LifetimeDefinition ().launchUnderBackgroundProgress(CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.cli.downloader.dialog.title" )) {
432428 try {
433429 this .indicator.text = " Authenticating client..."
434430 authenticate(deploymentURL, token.first)
@@ -456,51 +452,61 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
456452 tableOfWorkspaces.setEmptyState(CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text.connected" , deploymentURL.host))
457453 tfUrlComment?.text = CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text.connected" , deploymentURL.host)
458454 } catch (e: Exception ) {
459- val reason = e.message ? : CoderGatewayBundle .message(" gateway.connector.view.workspaces.connect.no-reason" )
460- val msg = when (e) {
461- is java.nio.file.AccessDeniedException -> CoderGatewayBundle .message(" gateway.connector.view.workspaces.connect.access-denied" , e.file)
462- is UnknownHostException -> CoderGatewayBundle .message(" gateway.connector.view.workspaces.connect.unknown-host" , e.message ? : deploymentURL.host)
463- is InvalidExitValueException -> CoderGatewayBundle .message(" gateway.connector.view.workspaces.connect.unexpected-exit" , e.exitValue)
464- is AuthenticationResponseException -> {
465- CoderGatewayBundle .message(
466- " gateway.connector.view.workspaces.connect.unauthorized" ,
467- deploymentURL,
468- )
469- }
470- is SocketTimeoutException -> {
471- CoderGatewayBundle .message(
472- " gateway.connector.view.workspaces.connect.timeout" ,
473- deploymentURL,
474- )
475- }
476- is ResponseException , is ConnectException -> {
477- CoderGatewayBundle .message(
478- " gateway.connector.view.workspaces.connect.download-failed" ,
479- reason,
480- )
455+ if (isCancellation(e)) {
456+ tfUrlComment?.text = CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text.comment" ,
457+ CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text" ))
458+ tableOfWorkspaces.setEmptyState(CoderGatewayBundle .message(
459+ " gateway.connector.view.workspaces.connect.canceled" ,
460+ deploymentURL.host,
461+ ))
462+ logger.info(" Connection canceled due to ${e.javaClass.simpleName} " )
463+ } else {
464+ val reason = e.message ? : CoderGatewayBundle .message(" gateway.connector.view.workspaces.connect.no-reason" )
465+ val msg = when (e) {
466+ is java.nio.file.AccessDeniedException -> CoderGatewayBundle .message(" gateway.connector.view.workspaces.connect.access-denied" , e.file)
467+ is UnknownHostException -> CoderGatewayBundle .message(" gateway.connector.view.workspaces.connect.unknown-host" , e.message ? : deploymentURL.host)
468+ is InvalidExitValueException -> CoderGatewayBundle .message(" gateway.connector.view.workspaces.connect.unexpected-exit" , e.exitValue)
469+ is AuthenticationResponseException -> {
470+ CoderGatewayBundle .message(
471+ " gateway.connector.view.workspaces.connect.unauthorized" ,
472+ deploymentURL,
473+ )
474+ }
475+ is SocketTimeoutException -> {
476+ CoderGatewayBundle .message(
477+ " gateway.connector.view.workspaces.connect.timeout" ,
478+ deploymentURL,
479+ )
480+ }
481+ is ResponseException , is ConnectException -> {
482+ CoderGatewayBundle .message(
483+ " gateway.connector.view.workspaces.connect.download-failed" ,
484+ reason,
485+ )
486+ }
487+ is SSLHandshakeException -> {
488+ CoderGatewayBundle .message(
489+ " gateway.connector.view.workspaces.connect.ssl-error" ,
490+ deploymentURL.host,
491+ reason,
492+ )
493+ }
494+ else -> reason
481495 }
482- is SSLHandshakeException -> {
483- CoderGatewayBundle .message(
484- " gateway.connector.view.workspaces.connect.ssl-error" ,
485- deploymentURL.host,
486- reason,
487- )
496+ // It would be nice to place messages directly into the table
497+ // but it does not support wrapping or markup so place it in the
498+ // comment field of the URL input instead.
499+ tfUrlComment?.foreground = UIUtil .getErrorForeground()
500+ tfUrlComment?.text = msg
501+ tableOfWorkspaces.setEmptyState(CoderGatewayBundle .message(
502+ " gateway.connector.view.workspaces.connect.failed" ,
503+ deploymentURL.host,
504+ ))
505+ logger.error(msg, e)
506+
507+ if (e is AuthenticationResponseException ) {
508+ cs.launch { onAuthFailure?.invoke() }
488509 }
489- else -> reason
490- }
491- // It would be nice to place messages directly into the table
492- // but it does not support wrapping or markup so place it in the
493- // comment field of the URL input instead.
494- tfUrlComment?.foreground = UIUtil .getErrorForeground()
495- tfUrlComment?.text = msg
496- tableOfWorkspaces.setEmptyState(CoderGatewayBundle .message(
497- " gateway.connector.view.workspaces.connect.failed" ,
498- deploymentURL.host,
499- ))
500- logger.error(msg, e)
501-
502- if (e is AuthenticationResponseException ) {
503- cs.launch { onAuthFailure?.invoke() }
504510 }
505511 }
506512 }
0 commit comments