@@ -83,6 +83,7 @@ function executeContributionGraphRequests(string $user, array $years): array
83
83
removeGitHubToken ($ tokens [$ year ]);
84
84
}
85
85
error_log ("First attempt to decode response for $ user's $ year contributions failed. $ message " );
86
+ error_log ("Contents: $ contents " );
86
87
// retry request
87
88
$ query = buildContributionGraphQuery ($ user , $ year );
88
89
$ token = getGitHubToken ();
@@ -96,6 +97,7 @@ function executeContributionGraphRequests(string $user, array $years): array
96
97
removeGitHubToken ($ token );
97
98
}
98
99
error_log ("Failed to decode response for $ user's $ year contributions after 2 attempts. $ message " );
100
+ error_log ("Contents: $ contents " );
99
101
continue ;
100
102
}
101
103
}
@@ -120,7 +122,11 @@ function getContributionGraphs(string $user): array
120
122
// get the list of years the user has contributed and the current year's contribution graph
121
123
$ currentYear = intval (date ("Y " ));
122
124
$ responses = executeContributionGraphRequests ($ user , [$ currentYear ]);
123
- $ contributionYears = $ responses [$ currentYear ]->data ->user ->contributionsCollection ->contributionYears ;
125
+ $ contributionYears = $ responses [$ currentYear ]->data ->user ->contributionsCollection ->contributionYears ?? [];
126
+ // if there are no contribution years, an API error must have occurred
127
+ if (empty ($ contributionYears )) {
128
+ throw new AssertionError ("Failed to retrieve contributions. This is likely a GitHub API issue. " , 500 );
129
+ }
124
130
// remove the current year from the list since it's already been fetched
125
131
$ contributionYears = array_filter ($ contributionYears , function ($ year ) use ($ currentYear ) {
126
132
return $ year !== $ currentYear ;
0 commit comments