From 9c667f4b7861f0ccb9450db1ec9f028d63723490 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 15 Mar 2022 15:37:41 +0600 Subject: [PATCH] several fixes in actual temporal upload of js client --- .../micro_utils/ktor/client/ActualTemporalUpload.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ktor/client/src/jsMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt b/ktor/client/src/jsMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt index 98070bd2430..0824c19c516 100644 --- a/ktor/client/src/jsMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt +++ b/ktor/client/src/jsMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt @@ -28,22 +28,26 @@ suspend fun tempUpload( if (request.status == 200.toShort()) { answer.complete(TemporalFileId(request.responseText)) } else { - answer.completeExceptionally(Exception("Something went wrong")) + answer.completeExceptionally(Exception("Something went wrong: $it")) } } request.onerror = { - answer.completeExceptionally(Exception("Something went wrong")) + answer.completeExceptionally(Exception("Something went wrong: $it")) } request.open("POST", fullTempUploadDraftPath, true) request.send(formData) - currentCoroutineContext().job.invokeOnCompletion { + val handle = currentCoroutineContext().job.invokeOnCompletion { runCatching { request.abort() } } - return answer.await() + return runCatching { + answer.await() + }.also { + handle.dispose() + }.getOrThrow() }