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

Return proper HTTP response codes for errors #59

Open
DenverCoder1 opened this issue Oct 4, 2021 · 6 comments
Open

Return proper HTTP response codes for errors #59

DenverCoder1 opened this issue Oct 4, 2021 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers up for grabs Looking for new contributors

Comments

@DenverCoder1
Copy link
Owner

DenverCoder1 commented Oct 4, 2021

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.

@DenverCoder1 DenverCoder1 added enhancement New feature or request good first issue Good for newcomers labels Oct 4, 2021
@DenverCoder1 DenverCoder1 added this to To do in Readme Typing SVG Projects via automation Oct 4, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2021

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

@github-actions github-actions bot added the no-issue-activity No activity in 30+ days label Nov 4, 2021
@DenverCoder1 DenverCoder1 removed the no-issue-activity No activity in 30+ days label Nov 4, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2021

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

@github-actions github-actions bot added the no-issue-activity No activity in 30+ days label Dec 5, 2021
@DenverCoder1 DenverCoder1 removed the no-issue-activity No activity in 30+ days label Dec 5, 2021
@DenverCoder1 DenverCoder1 added the up for grabs Looking for new contributors label Oct 2, 2022
@Vyvy-vi
Copy link
Contributor

Vyvy-vi commented Oct 14, 2022

I'd like to work on this.

@DenverCoder1
Copy link
Owner Author

@Vyvy-vi Go for it 👍

@mpa12
Copy link
Contributor

mpa12 commented Jul 1, 2024

@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;
    }

@DenverCoder1
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers up for grabs Looking for new contributors
Development

No branches or pull requests

3 participants