|
@@ -2,12 +2,20 @@
|
|
|
|
|
|
namespace Dcat\Admin\Exception;
|
|
|
|
|
|
+use Dcat\Admin\Contracts\ExceptionHandler;
|
|
|
use Dcat\Admin\Support\Helper;
|
|
|
use Illuminate\Support\MessageBag;
|
|
|
use Illuminate\Support\ViewErrorBag;
|
|
|
|
|
|
-class Handler
|
|
|
+class Handler implements ExceptionHandler
|
|
|
{
|
|
|
+ /**
|
|
|
+ * 处理异常.
|
|
|
+ *
|
|
|
+ * @param \Throwable $e
|
|
|
+ *
|
|
|
+ * @return array|string|void
|
|
|
+ */
|
|
|
public function handle(\Throwable $e)
|
|
|
{
|
|
|
$this->report($e);
|
|
@@ -15,6 +23,15 @@ class Handler
|
|
|
return $this->render($e);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 显示异常信息.
|
|
|
+ *
|
|
|
+ * @param \Throwable $exception
|
|
|
+ *
|
|
|
+ * @return array|string|void
|
|
|
+ *
|
|
|
+ * @throws \Throwable
|
|
|
+ */
|
|
|
public function render(\Throwable $exception)
|
|
|
{
|
|
|
if (config('app.debug')) {
|
|
@@ -39,23 +56,21 @@ class Handler
|
|
|
return view('admin::partials.exception', compact('errors'))->render();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 上报异常信息.
|
|
|
+ *
|
|
|
+ * @param \Throwable $e
|
|
|
+ */
|
|
|
public function report(\Throwable $e)
|
|
|
{
|
|
|
- $this->logger()->error($this->convertExceptionToString($e));
|
|
|
- }
|
|
|
-
|
|
|
- protected function convertExceptionToString(\Throwable $e)
|
|
|
- {
|
|
|
- return sprintf(
|
|
|
- "[%s] %s, called in %s(%s)\n%s",
|
|
|
- get_class($e),
|
|
|
- $e->getMessage(),
|
|
|
- $this->replaceBasePath($e->getFile()),
|
|
|
- $e->getLine(),
|
|
|
- $this->replaceBasePath($e->getTraceAsString())
|
|
|
- );
|
|
|
+ report($e);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param string $path
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
protected function replaceBasePath(string $path)
|
|
|
{
|
|
|
return str_replace(
|
|
@@ -64,9 +79,4 @@ class Handler
|
|
|
str_replace('\\', '/', $path)
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
- protected function logger()
|
|
|
- {
|
|
|
- return logger();
|
|
|
- }
|
|
|
}
|