Skip to content

Commit

Permalink
kpkg: downloader: add raiseWhenFail instead of prev commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kreatoo committed Sep 22, 2023
1 parent 2e4f4a7 commit 9dfca04
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions kpkg/modules/downloader.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ proc onProgressChanged(total, progress, speed: BiggestInt) =
stdout.flushFile

proc download*(url: string, file: string, instantErrorIfFail = false,
errWhenFail = true) =
raiseWhenFail = false) =
try:
var client = newHttpClient()
client.onProgressChanged = onProgressChanged
client.downloadFile(url, file&".partial")
moveFile(file&".partial", file)
echo ""
except Exception:
if instantErrorIfFail and errWhenFail:
err "download failed"
if instantErrorIfFail:
if raiseWhenFail:
raise newException(OSError, "download failed")
else:
err "download failed"
warn "download failed, retrying"
download(url, file, true)

0 comments on commit 9dfca04

Please sign in to comment.