How to use the socketshark.exceptions.EventError function in socketshark

To help you get started, we’ve selected a few socketshark 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 closeio / socketshark / socketshark / subscription.py View on Github external
async def message(self, event):
        """
        Sends a message to the subscription.
        """
        if self.name not in self.session.subscriptions:
            raise EventError(c.ERR_SUBSCRIPTION_NOT_FOUND)

        message_data = event.data.get('data')

        result = await self.on_message(message_data)
        if 'data' in result:
            if event:
                await event.send_ok(result['data'])
github closeio / socketshark / socketshark / events.py View on Github external
async def full_process(self):
        """
        Fully process an event and return whether it was successful.
        """
        try:
            return await self.process()
        except EventError as e:
            await self.send_error(e.error, data=e.data)
            return False
github closeio / socketshark / socketshark / subscription.py View on Github external
async def perform_service_request(self, service_event, extra_data={},
                                      error_message=None, raise_error=True):
        if service_event in self.service_config:
            url = self.service_config[service_event]
            data = self.prepare_service_data()
            data.update(extra_data)
            result = await http_post(self.shark, url, data)
            if raise_error and result.get('status') != 'ok':
                raise EventError(result.get('error', error_message or
                                            c.ERR_UNHANDLED_EXCEPTION),
                                 data=result.get('data'))
            return result
        return {'status': 'ok'}