【发布时间】:2022-01-31 01:38:30
【问题描述】:
所以我需要一些帮助来构建我的一种使用 ID 检索 Twitter 列表的方法。下面,我将描述并详细介绍它返回的内容。
代码:
public static function get_list($list_id)
{
$lists = self::get_lists();
$params = [
'list.fields' => 'created_at,follower_count,member_count,private,description,owner_id',
'user.fields' => 'created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld'
];
try {
$list = $lists->get($list_id, $params);
} catch (\GuzzleHttp\Exception\ClientException $e) {
return $e;
}
return $list;
}
当$lists->get()出现问题时,会抛出以下object(GuzzleHttp\Exception\ClientException)#1640 (10) { ["request":"GuzzleHttp\Exception\RequestException":private]=>错误。
我想要实现的目标:
返回 $e 以便我可以读取错误(无法使其正常工作)。
如果我将return $e 切换为return 'Hello',我仍然会看到对象而不是字符串。
IDE 建议它@throws GuzzleException。
在我处理异常的方式以及为什么我无法正确返回异常错误方面,是否有人认为有什么问题?
【问题讨论】: