Skip to content

Commit 0b018d0

Browse files
Release v0.5.1 (#61)
2 parents 44d5c15 + fba709c commit 0b018d0

File tree

3 files changed

+951
-1051
lines changed

3 files changed

+951
-1051
lines changed

app/Exceptions/Handler.php

-62
This file was deleted.

bootstrap/app.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3+
use Illuminate\Database\Eloquent\ModelNotFoundException;
34
use Illuminate\Foundation\Application;
45
use Illuminate\Foundation\Configuration\Exceptions;
56
use Illuminate\Foundation\Configuration\Middleware;
67
use Illuminate\Routing\Middleware\SubstituteBindings;
78
use Illuminate\Support\Facades\Route;
9+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
810

911
return Application::configure(basePath: dirname(__DIR__))
1012
->withRouting(
@@ -22,5 +24,12 @@
2224
//
2325
})
2426
->withExceptions(function (Exceptions $exceptions) {
25-
//
27+
$exceptions->render(function (NotFoundHttpException $e, \Illuminate\Http\Request $request) {
28+
if ($request->wantsJson() && $e->getPrevious() instanceof ModelNotFoundException) {
29+
return response()->json([
30+
'message' =>
31+
sprintf('Requested %s couldn\'t be found.', class_basename($e->getPrevious()->getModel())),
32+
], 404);
33+
}
34+
});
2635
})->create();

0 commit comments

Comments
 (0)