This commit is contained in:
pbao9
2026-02-11 11:18:35 +07:00
parent d59b2a0840
commit 6b6385f441
27 changed files with 386 additions and 30 deletions
+27 -2
View File
@@ -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);
});
}
}