1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-22 08:12:27 +00:00

Improve error handling

This commit is contained in:
J. Fernando Sánchez 2018-01-18 13:25:20 +01:00
parent dcaaa591b7
commit 23c88d0acc
2 changed files with 9 additions and 19 deletions

View File

@ -16,7 +16,6 @@ import os
import copy import copy
import errno import errno
import logging import logging
import traceback
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -171,22 +170,14 @@ class Senpy(object):
by api.parse_call(). by api.parse_call().
""" """
logger.debug("analysing request: {}".format(request)) logger.debug("analysing request: {}".format(request))
try: entries = request.entries
entries = request.entries request.entries = []
request.entries = [] plugins = self._get_plugins(request)
plugins = self._get_plugins(request) results = request
results = request for i in self._process_entries(entries, results, plugins):
for i in self._process_entries(entries, results, plugins): results.entries.append(i)
results.entries.append(i) self.convert_emotions(results)
self.convert_emotions(results) logger.debug("Returning analysis result: {}".format(results))
logger.debug("Returning analysis result: {}".format(results))
except (Error, Exception) as ex:
if not isinstance(ex, Error):
msg = "Error during analysis: {} \n\t{}".format(ex,
traceback.format_exc())
ex = Error(message=msg, status=500)
logger.exception('Error returning analysis result')
raise ex
results.analysis = [i['plugin'].id for i in results.analysis] results.analysis = [i['plugin'].id for i in results.analysis]
return results return results

View File

@ -182,8 +182,7 @@ class ExtensionsTest(TestCase):
analyse(self.senpy, input='nothing', algorithm='MOCK') analyse(self.senpy, input='nothing', algorithm='MOCK')
assert False assert False
except Exception as ex: except Exception as ex:
assert 'generic exception on analysis' in ex['message'] assert 'generic exception on analysis' in str(ex)
assert ex['status'] == 500
def test_filtering(self): def test_filtering(self):
""" Filtering plugins """ """ Filtering plugins """