@@ -133,14 +133,14 @@ function fetchGraphQL(string $query): stdClass
133133 http_response_code (curl_getinfo ($ ch , CURLINFO_HTTP_CODE ));
134134 // Missing SSL certificate
135135 if (str_contains (curl_error ($ ch ), 'unable to get local issuer certificate ' )) {
136- throw new AssertionError ("You don't have a valid SSL Certificate installed or XAMPP. " );
136+ throw new AssertionError ("You don't have a valid SSL Certificate installed or XAMPP. " , 400 );
137137 }
138138 // Handle errors such as "Bad credentials"
139139 if ($ obj && $ obj ->message ) {
140- throw new AssertionError ("Error: $ obj ->message \n<!-- $ response --> " );
140+ throw new AssertionError ("Error: $ obj ->message \n<!-- $ response --> " , 401 );
141141 }
142142 // TODO: Make the $response part get passed into a custom error and render the commented details in the SVG card generator
143- throw new AssertionError ("An error occurred when getting a response from GitHub. \n<!-- $ response --> " );
143+ throw new AssertionError ("An error occurred when getting a response from GitHub. \n<!-- $ response --> " , 502 );
144144 }
145145 return $ obj ;
146146}
@@ -166,17 +166,17 @@ function getContributionYears(string $user): array
166166 $ response = fetchGraphQL ($ query );
167167 // User not found
168168 if (!empty ($ response ->errors ) && $ response ->errors [0 ]->type === "NOT_FOUND " ) {
169- throw new InvalidArgumentException ("Could not find a user with that name. " );
169+ throw new InvalidArgumentException ("Could not find a user with that name. " , 404 );
170170 }
171171 // API Error
172172 if (!empty ($ response ->errors )) {
173173 // Other errors that contain a message field
174- throw new InvalidArgumentException ($ response ->errors [0 ]->message );
174+ throw new InvalidArgumentException ($ response ->errors [0 ]->message , 500 );
175175 }
176176 // API did not return data
177177 if (!isset ($ response ->data ) && isset ($ response ->message )) {
178178 // Other errors that contain a message field
179- throw new InvalidArgumentException ($ response ->message );
179+ throw new InvalidArgumentException ($ response ->message , 204 );
180180 }
181181 return $ response ->data ->user ->contributionsCollection ->contributionYears ;
182182}
@@ -196,7 +196,7 @@ function getContributionDates(array $contributionGraphs): array
196196 $ tomorrow = date ("Y-m-d " , strtotime ("tomorrow " ));
197197 foreach ($ contributionGraphs as $ graph ) {
198198 if (!empty ($ graph ->errors )) {
199- throw new AssertionError ($ graph ->data ->errors [0 ]->message );
199+ throw new AssertionError ($ graph ->data ->errors [0 ]->message , 502 );
200200 }
201201 $ weeks = $ graph ->data ->user ->contributionsCollection ->contributionCalendar ->weeks ;
202202 foreach ($ weeks as $ week ) {
@@ -225,7 +225,7 @@ function getContributionStats(array $contributions): array
225225{
226226 // if no contributions, display error
227227 if (empty ($ contributions )) {
228- throw new AssertionError ("No contributions found. " );
228+ throw new AssertionError ("No contributions found. " , 204 );
229229 }
230230 $ today = array_key_last ($ contributions );
231231 $ first = array_key_first ($ contributions );
0 commit comments