Update returned error codes
This commit is contained in:
@@ -90,15 +90,15 @@ 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 (bandwidth limit reached)", http.StatusLocked)
|
||||
http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf("Error unrestricting file %s: %v", file.Path, err)
|
||||
if file.State.Event(context.Background(), "break_file") == nil {
|
||||
torMgr.EnqueueForRepair(torrent)
|
||||
}
|
||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||
log.Errorf("Error unrestricting file %s: %v", file.Path, err)
|
||||
http.Error(resp, "File is not available (can't unrestrict)", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -134,12 +134,12 @@ 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 (bandwidth limit reached)", http.StatusLocked)
|
||||
http.Error(resp, "Link is not available (bandwidth limit reached)", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf("Error unrestricting link %s: %v", link, err)
|
||||
http.Error(resp, "File is not available", http.StatusInternalServerError)
|
||||
http.Error(resp, "File is not available (can't unrestrict)", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if cfg.ShouldServeFromRclone() {
|
||||
@@ -165,7 +165,7 @@ func (dl *Downloader) streamFileToResponse(
|
||||
if file != nil {
|
||||
log.Errorf("Error creating new request for file %s: %v", file.Path, err)
|
||||
}
|
||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||
http.Error(resp, "File is not available (can't create request)", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ func (dl *Downloader) streamFileToResponse(
|
||||
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)
|
||||
http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -187,7 +187,7 @@ func (dl *Downloader) streamFileToResponse(
|
||||
if file != nil && file.State.Event(context.Background(), "break_file") == nil {
|
||||
torMgr.EnqueueForRepair(torrent)
|
||||
}
|
||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||
http.Error(resp, "File is not available (can't download)", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
defer downloadResp.Body.Close()
|
||||
@@ -198,7 +198,7 @@ func (dl *Downloader) streamFileToResponse(
|
||||
if file != nil && file.State.Event(context.Background(), "break_file") == nil {
|
||||
torMgr.EnqueueForRepair(torrent)
|
||||
}
|
||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||
http.Error(resp, "File is not available (download error)", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user