【发布时间】:2018-02-19 01:50:50
【问题描述】:
我正在尝试处理错误,因为如果 $apimodel 变量为空或其他错误,我想重定向用户。就像 api 的身份验证错误等等。这是我的代码:
$integration = Integration::where('name', 'lightspeed')->first();
$apimodel = Apimodel::where('user_id', Auth::user()->id)
->where('integration_id', $integration->id)
->where('active', true)
->first();
try {
$api = new WebshopappApiClient(
$apimodel->data01,
$apimodel->api_key,
$apimodel->api_secret,
$apimodel->data02);
} catch (ErrorException $e) {
die($e->getMessage());
}
return view('integrations.lightspeed.index', compact('api'));
【问题讨论】:
-
你忘了问问题。您也没有解释“不起作用”的确切含义。
-
那么,WebshopappApiClient 类在失败时会抛出异常吗?
-
@Qirel 是的,它会在失败时抛出异常
-
显然没有。展示它的实现。另外,
ErrorException的完全限定名称是什么 -
@zerkms 使用 Whoops\Exception\ErrorException;