forked from luciferous/jwt
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Is it possible to have specific exceptions so they can be caught accordingly?
At the moment I am having todo the following:
catch (UnexpectedValueException $e)
{
if($e->getMessage() == "Expired Token") {
// Logic Here
} else {
throw $e;
}
}
Instead I propose the following:
Declare an exception class (i.e. Exceptions.php)
class ExpiredTokenException extends \UnexpectedValueException {}
Handle it in the code
if (isset($payload->exp) && time() >= $payload->exp){
throw new ExpiredTokenException('Expired Token');
}
Catch It
catch (JWT\Exceptions\ExpiredTokenException $e)
{
// Logic Here
}
This can be caught much easier and would have backwards compatibility with devs using UnexpectedValueException
.
Metadata
Metadata
Assignees
Labels
No labels