@@ -35,6 +35,7 @@ import kotlinx.coroutines.launch
3535import kotlinx.coroutines.selects.onTimeout
3636import kotlinx.coroutines.selects.select
3737import java.net.URI
38+ import java.util.UUID
3839import kotlin.coroutines.cancellation.CancellationException
3940import kotlin.time.Duration.Companion.seconds
4041import kotlin.time.TimeSource
@@ -302,31 +303,51 @@ class CoderRemoteProvider(
302303 * Handle incoming links (like from the dashboard).
303304 */
304305 override suspend fun handleUri (uri : URI ) {
305- linkHandler.handle(
306- uri, shouldDoAutoSetup(),
307- {
308- coderHeaderPage.isBusyCreatingNewEnvironment.update {
309- true
306+ try {
307+ linkHandler.handle(
308+ uri, shouldDoAutoSetup(),
309+ {
310+ coderHeaderPage.isBusyCreatingNewEnvironment.update {
311+ true
312+ }
313+ },
314+ {
315+ coderHeaderPage.isBusyCreatingNewEnvironment.update {
316+ false
317+ }
310318 }
311- },
312- {
313- coderHeaderPage.isBusyCreatingNewEnvironment.update {
319+ ) { restClient, cli ->
320+ // stop polling and de-initialize resources
321+ close()
322+ isInitialized.update {
314323 false
315324 }
325+ // start initialization with the new settings
326+ this @CoderRemoteProvider.client = restClient
327+ coderHeaderPage.setTitle(context.i18n.pnotr(restClient.url.toString()))
328+
329+ environments.showLoadingMessage()
330+ pollJob = poll(restClient, cli)
331+ isInitialized.waitForTrue()
316332 }
317- ) { restClient, cli ->
318- // stop polling and de-initialize resources
319- close()
320- isInitialized.update {
333+ } catch (ex: Exception ) {
334+ context.logger.error(ex, " " )
335+ val textError = if (ex is APIResponseException ) {
336+ if (! ex.reason.isNullOrBlank()) {
337+ ex.reason
338+ } else ex.message
339+ } else ex.message
340+
341+ context.ui.showSnackbar(
342+ UUID .randomUUID().toString(),
343+ context.i18n.ptrl(" Error encountered while handling Coder URI" ),
344+ context.i18n.pnotr(textError ? : " " ),
345+ context.i18n.ptrl(" Dismiss" )
346+ )
347+ } finally {
348+ coderHeaderPage.isBusyCreatingNewEnvironment.update {
321349 false
322350 }
323- // start initialization with the new settings
324- this @CoderRemoteProvider.client = restClient
325- coderHeaderPage.setTitle(context.i18n.pnotr(restClient.url.toString()))
326-
327- environments.showLoadingMessage()
328- pollJob = poll(restClient, cli)
329- isInitialized.waitForTrue()
330351 }
331352 }
332353
0 commit comments