several fixes in actual temporal upload of js client

This commit is contained in:
InsanusMokrassar 2022-03-15 15:37:41 +06:00
parent 21195e1bcb
commit 9c667f4b78

View File

@ -28,22 +28,26 @@ suspend fun tempUpload(
if (request.status == 200.toShort()) { if (request.status == 200.toShort()) {
answer.complete(TemporalFileId(request.responseText)) answer.complete(TemporalFileId(request.responseText))
} else { } else {
answer.completeExceptionally(Exception("Something went wrong")) answer.completeExceptionally(Exception("Something went wrong: $it"))
} }
} }
request.onerror = { request.onerror = {
answer.completeExceptionally(Exception("Something went wrong")) answer.completeExceptionally(Exception("Something went wrong: $it"))
} }
request.open("POST", fullTempUploadDraftPath, true) request.open("POST", fullTempUploadDraftPath, true)
request.send(formData) request.send(formData)
currentCoroutineContext().job.invokeOnCompletion { val handle = currentCoroutineContext().job.invokeOnCompletion {
runCatching { runCatching {
request.abort() request.abort()
} }
} }
return answer.await() return runCatching {
answer.await()
}.also {
handle.dispose()
}.getOrThrow()
} }