Add some exception handling just in case

This commit is contained in:
Gavin M. Roy 2016-09-13 22:02:21 -04:00
parent a22c66fda5
commit 9ba7a5e82c

View file

@ -89,11 +89,15 @@ class InfluxDBMixin(object):
if hasattr(self, 'correlation_id'): if hasattr(self, 'correlation_id'):
self.influxdb.set_tag('correlation_id', self.correlation_id) self.influxdb.set_tag('correlation_id', self.correlation_id)
self.influxdb.set_tag('status_code', self._status_code) self.influxdb.set_tag('status_code', self._status_code)
ctype = self._headers['Content-Type'].decode('utf-8')
self.influxdb.set_tag('content_type', ctype.split(';')[0].strip())
self.influxdb.set_field('duration', self.request.request_time()) self.influxdb.set_field('duration', self.request.request_time())
self.influxdb.set_field('content_length', self.influxdb.set_field('content_length',
int(self._headers['Content-Length'])) int(self._headers['Content-Length']))
try:
ctype = self._headers['Content-Type'].decode('utf-8')
except (AttributeError, TypeError):
pass
else:
self.influxdb.set_tag('content_type', ctype.split(';')[0].strip())
add_measurement(self.influxdb) add_measurement(self.influxdb)