Skip to content

Commit

Permalink
restore custom "not found" Exception messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
gael-connan-cybex committed Jul 12, 2024
1 parent 0d27eb9 commit 05858c0
Show file tree
Hide file tree
Showing 3 changed files with 2,745 additions and 2,798 deletions.
62 changes: 0 additions & 62 deletions app/Exceptions/Handler.php

This file was deleted.

11 changes: 10 additions & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Support\Facades\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
Expand All @@ -22,5 +24,12 @@
//
})
->withExceptions(function (Exceptions $exceptions) {
//
$exceptions->render(function (NotFoundHttpException $e, \Illuminate\Http\Request $request) {
if ($request->wantsJson() && $e->getPrevious() instanceof ModelNotFoundException) {
return response()->json([
'message' =>
sprintf('Requested %s couldn\'t be found.', class_basename($e->getPrevious()->getModel())),
], 404);
}
});
})->create();
Loading

0 comments on commit 05858c0

Please sign in to comment.