florianv / laravel-swap

:dollar: Currency exchange rates for Laravel and Lumen

Home Page:https://florianv.github.io/laravel-swap/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The request call is null - Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON

komen205 opened this issue · comments

commented

Swap::latest('EUR/USD'); is throwing "Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON"
on function

public function getExchangeRate(ExchangeRateQuery $exchangeQuery): ExchangeRate

    {

        $exceptions = [];

 

        foreach ($this->services as $service) {

            if (!$service->supportQuery($exchangeQuery)) {

                continue;

            }

            try {

                return $service->getExchangeRate($exchangeQuery);

            } catch (\Throwable $e) {

                $exceptions[] = $e;

            }

        }

 

        throw new ChainException($exceptions);

    }

I tried to dump the request on HttpService and it returns null.
image
And for the buildRequest function, if I dump the $request or $this->requestFactory->createRequest('GET', $url); returns

image

If I dump the $content in the private function doCreateRate in the AbstractApi.php file, it just returns nothing.
I can't find where the problem is. Any ideas?
image

I have the same issue

Looks like it's an issue with AbstractApi's response?

The issue has been documented here: https://github.com/florianv/exchanger/blob/master/doc/readme.md#configuration

You need to setup the curl client to follow location:

$options = [
    CURLOPT_FOLLOWLOCATION => true,
];
$client = new CurlClient(null, null, $options);