首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有消息的异常'Viewflex\Forex\ForexException‘检索汇率错误

带有消息的异常'Viewflex\Forex\ForexException‘检索汇率错误
EN

Stack Overflow用户
提问于 2018-10-03 11:16:49
回答 1查看 52关注 0票数 2

我正在使用此软件包的版本"viewflex/forex":"^0.1.1“,但同时更新了以下货币的汇率-

代码语言:javascript
复制
$usdRate = $server->getRate('USD', 'INR');

获取错误,如下面的异常'Viewflex\Forex\ForexException‘与消息’错误检索汇率。

任何帮助!谢谢,

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-03 11:33:13

查看他们的灵魂代码,我看到了以下内容:

https://github.com/viewflex/forex/blob/master/src/Forex.php#L57-L68

代码语言:javascript
复制
        if (
            array_key_exists('rates', $content)
            && array_key_exists($target, $content['rates'])
            && $content['rates'][$target]
        ) {
            $rate = floatval($content['rates'][$target]);
        } else {
            throw new ForexException('Error retrieving exchange rate.');
        }
        if($rate <= 0)
            throw new ForexException('Error retrieving exchange rate.');

因此,如果响应不包含所需的信息,它将抛出异常。另外,如果它通过了第一个检查,但是速率小于0,它也会抛出一个异常。所以看起来你并没有做错什么。

再往前看,我看到它发出了这样的呼吁:

代码语言:javascript
复制
$response = $this->request('https://api.fixer.io/latest?base='.$source.'&symbols='.$target);

我根据您的代码将此翻译为:

https://api.fixer.io/latest?base=USD&symbols=INR

如果你点击这个链接,就会给你答案:

代码语言:javascript
复制
0   "#################################################################################################################################"
1   "#                                                                                                                               #"
2   "# IMPORTANT - PLEASE UPDATE YOUR API ENDPOINT                                                                                   #"
3   "#                                                                                                                               #"
4   "# This API endpoint is deprecated and has now been shut down. To keep using the Fixer API, please update your integration       #"
5   "# to use the new Fixer API endpoint, designed as a simple drop-in replacement.                                                  #"
6   "# You will be required to create an account at https://fixer.io and obtain an API access key.                                   #"
7   "#                                                                                                                               #"
8   "# For more information on how to upgrade please visit our Github Tutorial at: https://github.com/fixerAPI/fixer#readme          #"
9   "#                                                                                                                               #"
a   "#################################################################################################################################"

看来图书馆已经过时了。

要么使用不同的库,要么让它再次工作。

要解决这个问题,您可以首先使用新的api创建一个帐户,如果您还没有注册github,那么可以分叉存储库,更改此行的https://github.com/viewflex/forex/blob/master/src/Forex.php#L53,或者发送拉请求,或者更改编写器包名https://github.com/viewflex/forex/blob/master/composer.json#L2,然后向https://packagist.org/注册自己的新包(如果这样做,也可以更改所有的文件命名空间)。

如果您注册了新的API并发送了新的端点,我可以向这个家伙发送一个带有补丁的拉请求。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52625868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档