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

Execption handling #10

Open
mascoda opened this issue Jul 31, 2021 · 2 comments
Open

Execption handling #10

mascoda opened this issue Jul 31, 2021 · 2 comments

Comments

@mascoda
Copy link

mascoda commented Jul 31, 2021

If i try to get coin data there no exists, it will a execption come.

Client error: GET https://api.coingecko.com/api/v3/coins/beluga.fi?tickers=true&market_data=true&sparkline=true` resulted in a 404 Not Found response: {"error":"Could not find coin with the given id"} `

This Execption cant be catcht, because there are come from GUZZLE Client.

How can i catch these exeptions?

Currently i have to change the CoinGeckoClient Constructor and add a new parameter, like

$this->httpClient = $client ?: new Client(['base_uri' => self::BASE_URI, 'http_errors' => false]);

That feel like bad.

@usrNotFound
Copy link

usrNotFound commented Aug 18, 2021

so 404 is a valid response do think there's any issue with API. You will need to probably catch 404 using try catch

@goatrance
Copy link

goatrance commented Apr 20, 2022

https://github.com/codenix-sv/coingecko-api/blob/master/src/Api/Api.php

public function get(string $uri, array $query = []): array
{
    try {
        $response = $this->client->getHttpClient()->request('GET', '/api/' . $this->version
            . $uri, ['query' => $query]);
    } catch (\Exception $e) {
        $response = $e->getResponse();
    }
    $this->client->setLastResponse($response);

    return $this->transformer->transform($response);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants