2023-06-10 14:21:40 +08:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
|
|
|
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
|
|
|
* https://www.x-lf.com/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Exceptions;
|
|
|
|
|
2023-07-09 15:41:04 +08:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
2023-06-10 14:21:40 +08:00
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
2023-07-09 15:41:04 +08:00
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
2023-06-10 14:21:40 +08:00
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
class Handler extends ExceptionHandler
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* A list of the exception types that are not reported.
|
|
|
|
*
|
|
|
|
* @var array<int, class-string<Throwable>>
|
|
|
|
*/
|
|
|
|
protected $dontReport = [
|
|
|
|
//
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of the inputs that are never flashed for validation exceptions.
|
|
|
|
*
|
|
|
|
* @var array<int, string>
|
|
|
|
*/
|
|
|
|
protected $dontFlash = [
|
|
|
|
'current_password',
|
|
|
|
'password',
|
|
|
|
'password_confirmation',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the exception handling callbacks for the application.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2023-07-09 15:41:04 +08:00
|
|
|
public function register(): void
|
2023-06-10 14:21:40 +08:00
|
|
|
{
|
|
|
|
$this->reportable(function (Throwable $e) {
|
|
|
|
//
|
|
|
|
});
|
|
|
|
}
|
2023-07-09 15:41:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 处理发现页面找不到之后返回内容
|
|
|
|
*
|
|
|
|
* @param Request $request 获取请求内容
|
|
|
|
* @param Throwable $e 抛出错误
|
|
|
|
* @return Response|JsonResponse|\Symfony\Component\HttpFoundation\Response|RedirectResponse
|
|
|
|
* @throws Throwable
|
|
|
|
*/
|
|
|
|
public function render($request, Throwable $e): Response|JsonResponse|\Symfony\Component\HttpFoundation\Response|RedirectResponse
|
|
|
|
{
|
|
|
|
if ($e instanceof ModelNotFoundException || $e instanceof NotFoundHttpException) {
|
|
|
|
return response()->redirectToRoute('404');
|
|
|
|
}
|
|
|
|
return parent::render($request, $e);
|
|
|
|
}
|
2023-06-10 14:21:40 +08:00
|
|
|
}
|