Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'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',
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()
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'}