class AuthenticationService {

    protected RuntimeException handleJwtParserException(RuntimeException exception) {
        if (exception instanceof ExpiredJwtException) {
            final ExpiredJwtException expiredJwtException = (ExpiredJwtException) exception;
            log.debug("Token with id '{}' for user '{}' is expired.", expiredJwtException.getClaims().getId(), expiredJwtException.getClaims().getSubject());
            return new TokenExpireException("Token is expired.");
        }
        if (exception instanceof JwtException) {
            log.debug(TOKEN_IS_NOT_VALID_DUE_TO, exception.getMessage());
            return new TokenNotValidException("Token is not valid.");
        }

        log.debug(TOKEN_IS_NOT_VALID_DUE_TO, exception.getMessage());
        return new TokenNotValidException("An internal error occurred while validating the token therefore the token is no longer valid.");
    }

}