How to use the zulip.ZulipError function in zulip

To help you get started, we’ve selected a few zulip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zulip / zulip-terminal / tests / model / test_model.py View on Github external
def test_init_ZulipError_exception(self, mocker, initial_data,
                                       exception_text="X"):
        # Both network calls fail, resulting in exceptions
        mocker.patch('zulipterminal.model.Model.get_messages',
                     side_effect=ZulipError(exception_text))
        mocker.patch('zulipterminal.model.Model._register_desired_events',
                     side_effect=ZulipError(exception_text))

        mocker.patch('zulipterminal.model.Model.get_all_users',
                     return_value=[])
        mocker.patch('zulipterminal.model.Model.'
                     '_stream_info_from_subscriptions',
                     return_value=({}, set(), [], []))
        self.classify_unread_counts = mocker.patch(
            'zulipterminal.model.classify_unread_counts',
            return_value=[])

        with pytest.raises(ServerConnectionFailure) as e:
            model = Model(self.controller)

        assert str(e.value) == exception_text + ' (get_messages, register)'
github zulip / python-zulip-api / zulip / integrations / bridge_with_matrix / matrix_bridge.py View on Github external
room = matrix_join_room(matrix_client, matrix_config)

            room.add_listener(matrix_to_zulip(zulip_client, zulip_config, matrix_config,
                                              options.no_noise))

            print("Starting listener thread on Matrix client")
            matrix_client.start_listener_thread()

            print("Starting message handler on Zulip client")
            zulip_client.call_on_each_message(zulip_to_matrix(zulip_config, room))

        except Bridge_FatalMatrixException as exception:
            sys.exit("Matrix bridge error: {}".format(exception))
        except Bridge_ZulipFatalException as exception:
            sys.exit("Zulip bridge error: {}".format(exception))
        except zulip.ZulipError as exception:
            sys.exit("Zulip error: {}".format(exception))
        except Exception as e:
            traceback.print_exc()
        backoff.fail()
github zulip / python-zulip-api / zulip_bots / zulip_bots / lib.py View on Github external
def __init__(
        self,
        client: Client,
        root_dir: str,
        bot_details: Dict[str, Any],
        bot_config_file: Optional[str]=None,
        bot_config_parser: Optional[configparser.ConfigParser]=None,
    ) -> None:
        # Only expose a subset of our Client's functionality
        try:
            user_profile = client.get_profile()
        except ZulipError as e:
            print('''
                ERROR: {}

                Have you not started the server?
                Or did you mis-specify the URL?
                '''.format(e))
            sys.exit(1)

        if user_profile.get('result') == 'error':
            msg = user_profile.get('msg', 'unknown')
            print('''
                ERROR: {}
                '''.format(msg))
            sys.exit(1)

        self._rate_limit = RateLimit(20, 5)
github zulip / zulip-terminal / zulipterminal / model.py View on Github external
'message',
            'update_message_flags',
            'muted_topics',
            'realm_user',  # Enables cross_realm_bots
            'realm_user_groups',
            # zulip_version and zulip_feature_level are always returned in
            # POST /register from Feature level 3.
            'zulip_version',
        ]
        event_types = list(self.event_actions)
        try:
            response = self.client.register(event_types=event_types,
                                            fetch_event_types=fetch_types,
                                            client_gravatar=True,
                                            apply_markdown=True)
        except zulip.ZulipError as e:
            return str(e)

        if response['result'] == 'success':
            if fetch_data:
                self.initial_data.update(response)
            self.max_message_id = response['max_message_id']
            self.queue_id = response['queue_id']
            self.last_event_id = response['last_event_id']
            return ""
        return response['msg']