how to chage laravel passport response on access_token expire from
{
"message": "Unauthenticated."
}
to
{
"type": "error",
"status": 401,
"message": "Access Token expires",
}
You can add custom exception handling in your App\Exceptions\Handler.php
class. Add the following function if not already present. You are basicly catching the Authentication exception, and adding your own transformation to it.
use Illuminate\Http\Response;
use Illuminate\Auth\AuthenticationException;
public function render($request, Throwable $e)
{
if ($e instanceof AuthenticationException) {
return response()->json(
[
'type' => 'error',
'status' => Response::HTTP_UNAUTHORIZED,
'message' => 'Access Token expires',
],
Response::HTTP_UNAUTHORIZED
);
}
return parent::render($request, $e);
}