DenverCoder1 / readme-typing-svg

⚡ Dynamically generated, customizable SVG that gives the appearance of typing and deleting text for use on your profile page, repositories, or website.
https://readme-typing-svg.demolab.com
MIT License
5.56k stars 864 forks source link

Return proper HTTP response codes for errors #59

Closed DenverCoder1 closed 2 months ago

DenverCoder1 commented 2 years ago

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.

github-actions[bot] commented 2 years 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

github-actions[bot] commented 2 years 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

Vyvy-vi commented 1 year ago

I'd like to work on this.

DenverCoder1 commented 1 year ago

@Vyvy-vi Go for it :+1:

mpa12 commented 2 months ago

@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 commented 2 months ago

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

mpa12 commented 2 months ago

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