Update returned error codes
This commit is contained in:
@@ -198,6 +198,10 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
efficiency := response.ServedMB * 100 / denominator
|
||||
|
||||
if zr.initialTraffic > response.TrafficLogged {
|
||||
zr.initialTraffic = response.TrafficLogged
|
||||
}
|
||||
|
||||
out += fmt.Sprintf(`
|
||||
<tr>
|
||||
<td>Library Size</td>
|
||||
|
||||
@@ -26,7 +26,7 @@ type Handlers struct {
|
||||
api *realdebrid.RealDebrid
|
||||
workerPool *ants.Pool
|
||||
hosts []string
|
||||
initialTraffic int64
|
||||
initialTraffic uint64
|
||||
log *logutil.Logger
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
|
||||
}
|
||||
hs.initialTraffic = 0
|
||||
if _, ok := trafficDetails["real-debrid.com"]; ok {
|
||||
hs.initialTraffic = trafficDetails["real-debrid.com"]
|
||||
hs.initialTraffic = uint64(trafficDetails["real-debrid.com"])
|
||||
}
|
||||
|
||||
if cfg.GetUsername() != "" {
|
||||
|
||||
@@ -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