Closed DenverCoder1 closed 2 months ago
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
I'd like to work on this.
@Vyvy-vi Go for it :+1:
@DenverCoder1 Do you need constants to determine HTTP statuses?
The only place where I found a comparison of HTTP status: GoogleFontConverter->curlGetContents
/**
* Get the contents of a URL
*
* @param string $url The URL to fetch
* @return string Response from URL
*/
private static function curlGetContents($url): string
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//! THERE
if ($httpCode != 200) {
throw new InvalidArgumentException("Failed to fetch Google Font from API.");
}
return $response;
}
There are many ways it could be implemented, constants could help with readability so that sounds good to me
It will not be the same implementation of course, but here is a PR for a similar issue in another project https://github.com/DenverCoder1/github-readme-streak-stats/pull/192
Enums were added in PHP 8.1. I can update the PHP version to 8.1 and use them to solve this problem
There are many ways it could be implemented, constants could help with readability so that sounds good to me
It will not be the same implementation of course, but here is a PR for a similar issue in another project DenverCoder1/github-readme-streak-stats#192
Currently all responses return 200 (unless there is a server error, in which case 500).
It would be best to have specific codes for different types of errors to differentiate between them.
Example:
400 - Bad request
etc.