diff --git a/library/think/Error.php b/library/think/Error.php index c17292bf..42827424 100644 --- a/library/think/Error.php +++ b/library/think/Error.php @@ -110,6 +110,9 @@ class Error $handle = new $class; } else { $handle = new Handle; + if ($class instanceof \Closure) { + $handle->setRender($class); + } } } return $handle; diff --git a/library/think/exception/Handle.php b/library/think/exception/Handle.php index d975690e..f523db09 100644 --- a/library/think/exception/Handle.php +++ b/library/think/exception/Handle.php @@ -21,11 +21,16 @@ use think\Response; class Handle { - + protected $render; protected $ignoreReport = [ '\\think\\exception\\HttpException', ]; + public function setRender($render) + { + $this->render = $render; + } + /** * Report or log an exception. * @@ -78,6 +83,13 @@ class Handle */ 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) { return $this->renderHttpException($e); } else {