Catch download error case

This commit is contained in:
Ben Adrian Sarmiento
2024-06-24 02:32:31 +02:00
parent 3b26040f7e
commit f84298c724
3 changed files with 11 additions and 6 deletions

View File

@@ -64,7 +64,7 @@ func (dl *Downloader) DownloadFile(
unrestrict, err := torMgr.UnrestrictFile(file, cfg.ShouldServeFromRclone())
if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "File is not available", http.StatusLocked)
http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusLocked)
return
}
if err != nil {
@@ -108,7 +108,7 @@ func (dl *Downloader) DownloadLink(
unrestrict, err := torMgr.UnrestrictLink(link, cfg.ShouldServeFromRclone())
if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "Link is not available", http.StatusLocked)
http.Error(resp, "Link is not available (bandwidth limit reached)", http.StatusLocked)
return
}
if err != nil {
@@ -151,6 +151,11 @@ func (dl *Downloader) streamFileToResponse(
// Perform the request
downloadResp, err := dl.client.Do(dlReq)
if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusLocked)
return
}
if err != nil {
log.Warnf("Cannot download file %s: %v", unrestrict.Download, err)
if file != nil && file.State.Event(context.Background(), "break_file") == nil {