Skip to content

Commit

Permalink
Merge pull request #310 from Automattic/update/rate-limit-constant
Browse files Browse the repository at this point in the history
New exit status for HTTP API errors, update log message
  • Loading branch information
gudmdharalds authored Oct 20, 2022
2 parents 2f45d64 + ed68390 commit 17d9cbc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
define( 'VIPGOCI_EXIT_NORMAL', 0 );
define( 'VIPGOCI_EXIT_INTERNAL_ERROR', 220 );
define( 'VIPGOCI_EXIT_COMMIT_NOT_PART_OF_PR', 230 );
define( 'VIPGOCI_EXIT_HTTP_API_ERROR', 247 );
define( 'VIPGOCI_EXIT_COMMIT_NOT_LATEST', 248 );
define( 'VIPGOCI_EXIT_EXEC_TIME', 249 );
define( 'VIPGOCI_EXIT_CODE_ISSUES', 250 );
Expand Down
12 changes: 6 additions & 6 deletions http-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function vipgoci_http_resp_sunset_header_check(
}

/**
* Detect if we exceeded the API rate-limits,
* Detect if we exceeded the API rate limit,
* and if so, exit with error.
*
* @param string $http_api_url API URL used.
Expand Down Expand Up @@ -276,15 +276,15 @@ function vipgoci_http_api_rate_limits_check(
( $resp_headers['x-ratelimit-remaining'][0] <= 1 )
) {
vipgoci_sysexit(
'Ran out of request limits for API, cannot ' .
'Exceeded rate limit for HTTP API, unable to ' .
'continue without making further requests.',
array(
'http_api_url' => $http_api_url,
'x-ratelimit-remaining' => $resp_headers['x-ratelimit-remaining'][0],
'x-ratelimit-limit' => isset( $resp_headers['x-ratelimit-limit'][0] )
?? $resp_headers['x-ratelimit-limit'][0],
? $resp_headers['x-ratelimit-limit'][0] : null,
),
VIPGOCI_EXIT_GITHUB_PROBLEM,
VIPGOCI_EXIT_HTTP_API_ERROR,
true // Log to IRC.
);
}
Expand Down Expand Up @@ -547,9 +547,9 @@ function vipgoci_http_api_fetch_url(
( false === $resp_data )
) {
vipgoci_sysexit(
'Gave up retrying request to HTTP API, cannot continue',
'Gave up retrying request to HTTP API, can not continue',
array(),
VIPGOCI_EXIT_GITHUB_PROBLEM,
VIPGOCI_EXIT_HTTP_API_ERROR,
true // Log to IRC.
);
} elseif (
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/HttpFunctionsHttpApiRateLimitsCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ final class HttpFunctionsHttpApiRateLimitsCheckTest extends TestCase {
array(
'url' => 'https://api.github.com/v1',
'headers' => array( 'x-ratelimit-remaining' => array( '0' ) ),
'output' => '"Ran out of request limits for API, cannot continue without making further requests."' . PHP_EOL,
'output' => '"Exceeded rate limit for HTTP API, unable to continue without making further requests."' . PHP_EOL,
),
array(
'url' => 'https://api.github.com/v1',
'headers' => array( 'x-ratelimit-remaining' => array( '-1' ) ),
'output' => '"Ran out of request limits for API, cannot continue without making further requests."' . PHP_EOL,
'output' => '"Exceeded rate limit for HTTP API, unable to continue without making further requests."' . PHP_EOL,
),
array(
'url' => 'https://api.github.com/v1',
Expand All @@ -62,7 +62,7 @@ final class HttpFunctionsHttpApiRateLimitsCheckTest extends TestCase {
array(
'url' => 'https://wpscan.com/api/v3/plugins/test',
'headers' => array( 'x-ratelimit-remaining' => array( '0' ) ),
'output' => '"Ran out of request limits for API, cannot continue without making further requests."' . PHP_EOL,
'output' => '"Exceeded rate limit for HTTP API, unable to continue without making further requests."' . PHP_EOL,
),
array(
'url' => 'https://wpscan.com/api/v3/plugins/test',
Expand Down

0 comments on commit 17d9cbc

Please sign in to comment.