PILOS
PILOS copied to clipboard
Improve NotFoundExceptions
Is your feature request related to a problem? Please describe. At the moment you get a message like that "No query results for model [App\MODELNAME] ID" on 404 errors. That message is not translated and might not be easy to understand for users. We should implement a better solutution to show 404 errors that just the server generated message.
Describe the solution you'd like Implement a custom 404 handler like that in app/Exceptions/Handler.php and pass model name and not found ids to frontend and implement a better display solution there.
if ($request->ajax() || $request->wantsJson())
{
if ($exception instanceof ModelNotFoundException) {
$json = [
'message' => $exception->getMessage(),
'model' => $exception->getModel(),
'ids' => $exception->getIds(),
];
return response()->json($json, 404);
}
}
Describe alternatives you've considered Implement a custom 404 handler for each call, but that is propably not worth it and could still be used in some special cases.