首页 > 解决方案 > 我该如何处理流明异常?

问题描述

我想在发生错误时记录错误。

我的控制器是这样的:

  try {
    Wallet::create([
     'name' => 'TET',
   ]);
   } catch (QueryException $e) {
        $message = Str::contains($e->getMessage(), 'Deadlock') ? 'Server is busy' : $e->getMessage();
        throw new HttpException(400, $message);

    } catch (\Exception $e) {
        throw new HttpException(400, $e->getMessage());
    }
  

我的 App\Exceptions\Handler.php 是这样的:

public function report(Throwable $exception)
{
    if ($exception instanceof QueryException) {
        Log::error($exception->getMessage());
    }

    parent::report($exception);
}

但异常不是 QueryException 的 instanceof。

标签: phplaravellumen

解决方案


推荐阅读