How to use the socketshark.constants.ERR_UNHANDLED_EXCEPTION 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 / tests / test_basic.py View on Github external
'status': 'error',
                'error': 'before unsubscribe error',
            })
            mock.post(conf['before_unsubscribe'], payload={'status': 'ok'})
            mock.post(conf['on_unsubscribe'], payload={'doesnt': 'matter'})

            await session.on_client_event({
                'event': 'unsubscribe',
                'subscription': 'complex.topic',
            })
            assert client.log.pop() == {
                'event': 'unsubscribe',
                'subscription': 'complex.topic',
                'status': 'error',
                'extra': 'hello',
                'error': c.ERR_UNHANDLED_EXCEPTION,
            }

            await session.on_client_event({
                'event': 'unsubscribe',
                'subscription': 'complex.topic',
            })
            assert client.log.pop() == {
                'event': 'unsubscribe',
                'subscription': 'complex.topic',
                'status': 'error',
                'extra': 'hello',
                'error': 'before unsubscribe error',
            }

            await session.on_client_event({
                'event': 'unsubscribe',
github closeio / socketshark / socketshark / session.py View on Github external
self.log.debug('client event', data=data)
        event = Event.from_data(self, data)
        try:
            result = await event.full_process()

            # Don't log invalid/unknown event names
            if isinstance(event, InvalidEvent):
                event_name = 'invalid'
            elif isinstance(event, UnknownEvent):
                event_name = 'unknown'
            else:
                event_name = event.event
            self.shark.metrics.log_event(event_name, result)
        except:
            self.shark.log.exception('unhandled event processing exception')
            await event.send_error(c.ERR_UNHANDLED_EXCEPTION)
            await self.close()
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'}