exception
public function index()
{
throw new APIHttpException('wrong');
}
public function __construct($message = '', Exception $previous = null, array $headers = array(), $code = 0)
{
if (!$message) $message = $this->message;
parent::__construct($this->statusCode, $message, $previous, $headers, $code);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
##如果config配置debug为true ==>debug模式的话让laravel自行处理
if (config('app.debug')) {
return parent::render($request, $e);
}
return $this->handle($request, $e);
}
/**
* @param $request
* @param Exception $e
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
*/
public function handle($request, Exception $e)
{
##只处理自定义的APIException异常
if ($e instanceof APIHttpException) {
$result = [
"msg" => "",
"data" => $e->getMessage(),
"status" => 0
];
return response()->json($result);
}
return parent::render($request, $e);
}