-
-
Notifications
You must be signed in to change notification settings - Fork 795
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
Return proper HTTP response codes for errors #59
Comments
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 👍 |
@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 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.
The text was updated successfully, but these errors were encountered: