im working in developing a api in laravel, but im having some trouble handling errors messages.
For example if a user calls a endpoits with the rigth headers like "Content-Type => application/json" and "Accept => application/json", it returns a message in json just how should it do.
The problem is when the header for example "Accept..." is not inserted, it goes to the route login, and is working right, it should work since is what the script is doing.
protected function unauthenticated($request, AuthenticationException $exception)
{
return $request->expectsJson()
? response()->json(['success'=> false,'message' => $exception->getMessage(), 'code' => 9], 401)
: redirect()->guest($exception->redirectTo() ?? route('login'));
}
But when the Accept property is not inserted in the header it throw new InvalidArgumentException("Route [{$name}] not defined.");
How can i deal with this in the laravel api? I need this behaviour in the other hand because i will have in my laravel app my backend, and a part i have the api where i will share with a mobile app.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire