mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
several fixes in actual temporal upload of js client
This commit is contained in:
parent
21195e1bcb
commit
9c667f4b78
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user