mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 07:02:47 +08:00
exception_handle配置参数支持使用闭包定义render处理
This commit is contained in:
@@ -110,6 +110,9 @@ class Error
|
|||||||
$handle = new $class;
|
$handle = new $class;
|
||||||
} else {
|
} else {
|
||||||
$handle = new Handle;
|
$handle = new Handle;
|
||||||
|
if ($class instanceof \Closure) {
|
||||||
|
$handle->setRender($class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $handle;
|
return $handle;
|
||||||
|
|||||||
@@ -21,11 +21,16 @@ use think\Response;
|
|||||||
|
|
||||||
class Handle
|
class Handle
|
||||||
{
|
{
|
||||||
|
protected $render;
|
||||||
protected $ignoreReport = [
|
protected $ignoreReport = [
|
||||||
'\\think\\exception\\HttpException',
|
'\\think\\exception\\HttpException',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function setRender($render)
|
||||||
|
{
|
||||||
|
$this->render = $render;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report or log an exception.
|
* Report or log an exception.
|
||||||
*
|
*
|
||||||
@@ -78,6 +83,13 @@ class Handle
|
|||||||
*/
|
*/
|
||||||
public function render(Exception $e)
|
public function render(Exception $e)
|
||||||
{
|
{
|
||||||
|
if ($this->render && $this->render instanceof \Closure) {
|
||||||
|
$result = call_user_func_array($this->render, [$e]);
|
||||||
|
if ($result) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($e instanceof HttpException) {
|
if ($e instanceof HttpException) {
|
||||||
return $this->renderHttpException($e);
|
return $this->renderHttpException($e);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user