I am using Laravel 5.1 and I a'm trying to use Exception: TokenBlacklistedException and TokenExpiredException but it does not work. Rest Using Advanced Client for Chrome,
returns the following error.

does not return the message in the catch.
try {
if (! $user = JWTAuth::parseToken()->authenticate()) {
return response()->json(['user_not_found'], 404);
}
} catch (Tymon\JWTAuth\Exceptions\TokenBlacklistedException $e) {
return response()->json(['token_expired'], $e->getStatusCode());
}catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
return response()->json(['token_expired'], $e->getStatusCode());
} catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
return response()->json(['token_invalid'], $e->getStatusCode());
} catch (Tymon\JWTAuth\Exceptions\JWTException $e) {
return response()->json(['token_absent'], $e->getStatusCode());
}
Are you in a namespace? You'll either need leading slashes on the exceptions to escape them to the global namespace, or else use them so they're available in the file.
Yes, I am using:
use JWTAuth;
use TymonJWTAuthExceptionsJWTException;
use TymonJWTAuthExceptionsTokenExpiredException;
use TymonJWTAuthExceptionsTokenInvalidException;
use TymonJWTAuthExceptionsTokenBlacklistedException;
I'm not sure if I will need something to set
Thanks for you comment. Problem solved
I am use:
use TymonJWTAuthExceptionsJWTException;
use TymonJWTAuthExceptionsTokenExpiredException;
use TymonJWTAuthExceptionsTokenInvalidException;
use TymonJWTAuthExceptionsTokenBlacklistedException;
and:
try {
if (! $user = JWTAuth::parseToken()->authenticate()) {
return response()->json(['user_not_found'], 404);
}
} catch (TokenBlacklistedException $e) {
return response()->json(['token_expired'], $e->getStatusCode());
}catch (TokenExpiredException $e) {
return response()->json(['token_expired'], $e->getStatusCode());
} catch (TokenInvalidException $e) {
return response()->json(['token_invalid'], $e->getStatusCode());
} catch (JWTException $e) {
return response()->json(['token_absent'], $e->getStatusCode());
}
Yep sorry I wasn't clear. That's what I meant by the second option. :wink: Glad it worked out!
Nice working for me
great answer
Most helpful comment
Thanks for you comment. Problem solved
I am use:
use TymonJWTAuthExceptionsJWTException;
use TymonJWTAuthExceptionsTokenExpiredException;
use TymonJWTAuthExceptionsTokenInvalidException;
use TymonJWTAuthExceptionsTokenBlacklistedException;
and:
try {