From c1fdd9f5d1961df2919a2455937e9bad706d74ab Mon Sep 17 00:00:00 2001 From: Ben Adrian Sarmiento Date: Tue, 25 Jun 2024 16:25:12 +0200 Subject: [PATCH] Remove any fatal error messages to prevent crashes --- internal/app.go | 19 +++++++++++++++---- pkg/premium/monitor.go | 15 +++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/internal/app.go b/internal/app.go index 5fd8882..fc1f1e4 100644 --- a/internal/app.go +++ b/internal/app.go @@ -64,13 +64,24 @@ func MainApp(configPath string) { repoClient4 := http.NewHTTPClient("", 0, 1, false, []string{}, proxyURL, log.Named("network_test")) repoClient6 := http.NewHTTPClient("", 0, 1, true, []string{}, proxyURL, log.Named("network_test")) repo := http.NewIPRepository(repoClient4, repoClient6, "", log.Named("network_test")) - repo.NetworkTest(false, config.ShouldCacheNetworkTestResults()) - hosts := repo.GetHosts(config.GetNumberOfHosts(), config.ShouldForceIPv6()) + var hosts []string + repo.NetworkTest(false, config.ShouldCacheNetworkTestResults()) + hosts = repo.GetHosts(config.GetNumberOfHosts(), config.ShouldForceIPv6()) if len(hosts) == 0 { - zurglog.Fatal("No reachable hosts found. We cannot continue! (check if Real-Debrid is down or they have blocked your IP address)") + zurglog.Errorf("No reachable hosts found. Trying again.") + for { + repo.NetworkTest(true, config.ShouldCacheNetworkTestResults()) + hosts = repo.GetHosts(config.GetNumberOfHosts(), config.ShouldForceIPv6()) + if len(hosts) == 0 { + zurglog.Errorf("No reachable hosts found. Trying again in 5 minutes.") + time.Sleep(5 * time.Minute) + continue + } + zurglog.Debugf("Reachable hosts (%d): %v", len(hosts), hosts) + break + } } - zurglog.Debugf("Reachable hosts (%d): %v", len(hosts), hosts) apiClient := http.NewHTTPClient( config.GetToken(), diff --git a/pkg/premium/monitor.go b/pkg/premium/monitor.go index f40e6de..bd21173 100644 --- a/pkg/premium/monitor.go +++ b/pkg/premium/monitor.go @@ -14,15 +14,22 @@ const ( ) func MonitorPremiumStatus(workerPool *ants.Pool, rd *realdebrid.RealDebrid, zurglog *logutil.Logger) { - userInfo, err := rd.GetUserInformation() - if err != nil { - zurglog.Fatalf("Failed to get user information: %v", err) + var userInfo *realdebrid.User + var err error + for { + userInfo, err = rd.GetUserInformation() + if err != nil { + zurglog.Errorf("Failed to get user information: %v trying again in 30 seconds", err) + time.Sleep(30 * time.Second) + continue + } + break } workerPool.Submit(func() { for { if userInfo.Premium <= MINIMUM_SLEEP { - zurglog.Fatal("Your account is no longer premium, exiting...") + zurglog.Errorf("YOUR ACCOUNT IS NO LONGER PREMIUM. PLEASE RENEW YOUR SUBSCRIPTION.") } else { if userInfo.Premium <= PREMIUM_THRESHOLD { zurglog.Warnf("Your account will expire in %d hours", userInfo.Premium/3600)