Skip to content

Commit 78156a0

Browse files
committed
Custom API 404 error message
1 parent fc964f8 commit 78156a0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

app/Exceptions/Handler.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace App\Exceptions;
44

55
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
6-
use Throwable;
6+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
77

88
class Handler extends ExceptionHandler
99
{
@@ -34,8 +34,10 @@ class Handler extends ExceptionHandler
3434
*/
3535
public function register()
3636
{
37-
$this->reportable(function (Throwable $e) {
38-
//
37+
$this->renderable(function (NotFoundHttpException $e, $request) {
38+
if ($request->wantsJson()) {
39+
return response()->json(['message' => 'Object not found'], 404);
40+
}
3941
});
4042
}
4143
}

0 commit comments

Comments
 (0)