guessing-miniprogram/app/Exceptions/Handler.php

40 lines
1.0 KiB
PHP

<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class Handler extends ExceptionHandler
{
/**
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*/
public function register(): void
{
$this->reportable(function (Throwable $e) {
//
});
}
public function render($request, Throwable $e){
// // FirstOrFail 和 FindOrFail 异常处理
if ($e instanceof ModelNotFoundException) {
if ($request->ajax() || $request->wantsJson()) {
return response()->json(['data'=>null,'code'=>404 , 'message' => '数据未找到,或已被删除' ], 404);
}
}
}
}