8 Star 141 Fork 50

MZ/ModStartBlog

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Handler.php 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
MZ 提交于 2023-08-23 19:31 +08:00 . feat: blog password mode
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use ModStart\Core\Exception\BizException;
use ModStart\Core\Exception\ExceptionReportHandleTrait;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Handler extends ExceptionHandler
{
use ExceptionReportHandleTrait;
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
HttpException::class,
ModelNotFoundException::class,
BizException::class,
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
$this->errorReportCheck($exception);
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
$t = $this->getExceptionResponse($e);
if (null !== $t) {
return $t;
}
return parent::render($request, $e);
}
/**
* Convert the given exception into a Response instance.
*
* @param \Exception $e
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function convertExceptionToResponse(Exception $e)
{
$t = $this->getExceptionResponse($e);
if (null !== $t) {
return $t;
}
if (config('env.APP_DEBUG', true)) {
return parent::convertExceptionToResponse($e);
}
return response()->view('errors.500', ['exception' => $e], 500);
}
protected function shouldntReport(\Exception $e)
{
return $this->isExceptionIgnore($e) || parent::shouldntReport($e);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/modstart/ModStartBlog.git
git@gitee.com:modstart/ModStartBlog.git
modstart
ModStartBlog
ModStartBlog
master

搜索帮助