完成友链模块 #12

Merged
XiaoLFeng merged 25 commits from feature into master 2023-07-21 14:01:32 +08:00
Showing only changes of commit f4de7d71bd - Show all commits

View File

@ -7,7 +7,13 @@
namespace App\Exceptions; namespace App\Exceptions;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable; use Throwable;
class Handler extends ExceptionHandler class Handler extends ExceptionHandler
@ -37,10 +43,26 @@ class Handler extends ExceptionHandler
* *
* @return void * @return void
*/ */
public function register() public function register(): void
{ {
$this->reportable(function (Throwable $e) { $this->reportable(function (Throwable $e) {
// //
}); });
} }
/**
* 处理发现页面找不到之后返回内容
*
* @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);
}
} }