@@ -35,6 +35,7 @@ import kotlinx.coroutines.launch
35
35
import kotlinx.coroutines.selects.onTimeout
36
36
import kotlinx.coroutines.selects.select
37
37
import java.net.URI
38
+ import java.util.UUID
38
39
import kotlin.coroutines.cancellation.CancellationException
39
40
import kotlin.time.Duration.Companion.seconds
40
41
import kotlin.time.TimeSource
@@ -302,31 +303,51 @@ class CoderRemoteProvider(
302
303
* Handle incoming links (like from the dashboard).
303
304
*/
304
305
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
+ }
310
318
}
311
- },
312
- {
313
- coderHeaderPage.isBusyCreatingNewEnvironment.update {
319
+ ) { restClient, cli ->
320
+ // stop polling and de-initialize resources
321
+ close()
322
+ isInitialized.update {
314
323
false
315
324
}
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()
316
332
}
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 {
321
349
false
322
350
}
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()
330
351
}
331
352
}
332
353
0 commit comments