update
This commit is contained in:
@@ -34,8 +34,33 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
$this->renderable(function (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e, $request) {
|
||||
if (!$request->expectsJson() && !$request->is('v1/*') && !$request->is('api/*')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$previous = $e->getPrevious();
|
||||
|
||||
if ($previous instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {
|
||||
$modelClass = $previous->getModel();
|
||||
$pageType = match ($modelClass) {
|
||||
\App\Models\Product::class => 'service',
|
||||
\App\Models\Customer::class => 'client',
|
||||
\App\Models\Post::class => 'post',
|
||||
default => 'unknown',
|
||||
};
|
||||
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Dữ liệu không tồn tại',
|
||||
'page_type' => $pageType,
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'API Route not found',
|
||||
], 404);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user