fix(downloader): improve error reporting by returning nil for no error

This commit is contained in:
banbxio 2025-04-02 22:28:06 +08:00
parent 02609e6e1e
commit a1a11d482b

View File

@ -108,7 +108,12 @@ func downloadStatusHandler(downloaderCache *cache.Cache) handleFunc {
"url": taskCache.URL, "url": taskCache.URL,
"taskID": taskCache.TaskID.String(), "taskID": taskCache.TaskID.String(),
"status": taskCache.status, "status": taskCache.status,
"error": fmt.Sprint(taskCache.err), "error": func() interface{} {
if taskCache.err == nil {
return nil
}
return taskCache.err.Error()
}(),
} }
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(&responseBody) err := json.NewEncoder(w).Encode(&responseBody)