Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New exit status for HTTP API errors, update log message #310

Merged
merged 6 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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