【发布时间】:2017-10-03 02:56:05
【问题描述】:
我正在使用中止功能从我的服务层发送自定义异常消息。
if($max_users < $client->users()->count()){
return abort(401, "Max User Limit Exceeded");
}
但是如何在我的控制器中捕获此消息,该控制器位于不同的应用程序中
try{
$clientRequest = $client->request(
'POST',
"api/saveClientDetails",
[
'headers' => [
'accept' => 'application/json',
'authorization' => 'Bearer ' . $user['tokens']->access_token
],
'form_params' => $data,
]
);
} catch ( \GuzzleHttp\Exception\ClientException $clientException ){
switch($clientException->getCode()){
case 401:
\Log::info($clientException->getCode());
\Log::info($clientException->getMessage());
abort(401);
break;
default:
abort(500);
break;
}
}
上面的代码为消息打印以下内容:
但它会打印出来
Client error: `POST http://project-service.dev/api/saveClientDetails` resulted in a `401 Unauthorized` response:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow (truncated...)
【问题讨论】:
标签: laravel abort custom-errors