@@ -43,7 +43,9 @@ func Head(ctx context.Context, url, token string) error {
43
43
switch response .StatusCode {
44
44
case http .StatusOK :
45
45
requestRemaining := response .Header .Get ("X-RateLimit-Remaining" )
46
- logger .Log (ctx , slog .LevelDebug , "request remaining" , slog .String ("requestRemaining" , requestRemaining ))
46
+ if requestRemaining != "" {
47
+ logger .Log (ctx , slog .LevelDebug , "request remaining" , slog .String ("requestRemaining" , requestRemaining ))
48
+ }
47
49
return nil
48
50
49
51
case http .StatusTooManyRequests :
@@ -61,12 +63,20 @@ func Head(ctx context.Context, url, token string) error {
61
63
continue
62
64
63
65
case http .StatusNotFound :
66
+ logger .Log (ctx , slog .LevelDebug , "resource not found" , slog .String ("url" , url ))
64
67
return fmt .Errorf ("not found" )
65
68
66
69
default :
70
+ if response .StatusCode >= 500 && response .StatusCode < 600 {
71
+ logger .Log (ctx , slog .LevelWarn , "received server error, trying again in 5 seconds" , slog .String ("status" , response .Status ))
72
+ time .Sleep (5 * time .Second )
73
+ continue
74
+ }
75
+
67
76
return fmt .Errorf ("received unexpected status code %d with message: %v" , response .StatusCode , response .Body )
68
77
}
69
78
}
70
79
80
+ logger .Log (ctx , slog .LevelError , "max retries reached" )
71
81
return fmt .Errorf ("max retries reached: %v" , maxRetries )
72
82
}
0 commit comments