diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7c52374bb..e17af7d63 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -5,6 +5,7 @@ use App\Module\Base; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Support\Facades\Log; use Throwable; class Handler extends ExceptionHandler @@ -57,4 +58,18 @@ public function render($request, Throwable $e) } return parent::render($request, $e); } + + /** + * 重写report优雅记录 + * @param Throwable $e + * @throws Throwable + */ + public function report(Throwable $e) + { + if ($e instanceof ApiException) { + Log::error($e->getMessage(), ['exception' => ' at ' . $e->getFile() .':' . $e->getLine()]); + } else { + parent::report($e); + } + } }