From 23c88d0acc1dcb256b0feed91dc8151d6f12c6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 18 Jan 2018 13:25:20 +0100 Subject: [PATCH] Improve error handling --- senpy/extensions.py | 25 ++++++++----------------- tests/test_extensions.py | 3 +-- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/senpy/extensions.py b/senpy/extensions.py index facdc1c..462be2a 100644 --- a/senpy/extensions.py +++ b/senpy/extensions.py @@ -16,7 +16,6 @@ import os import copy import errno import logging -import traceback logger = logging.getLogger(__name__) @@ -171,22 +170,14 @@ class Senpy(object): by api.parse_call(). """ logger.debug("analysing request: {}".format(request)) - try: - entries = request.entries - request.entries = [] - plugins = self._get_plugins(request) - results = request - for i in self._process_entries(entries, results, plugins): - results.entries.append(i) - self.convert_emotions(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 + entries = request.entries + request.entries = [] + plugins = self._get_plugins(request) + results = request + for i in self._process_entries(entries, results, plugins): + results.entries.append(i) + self.convert_emotions(results) + logger.debug("Returning analysis result: {}".format(results)) results.analysis = [i['plugin'].id for i in results.analysis] return results diff --git a/tests/test_extensions.py b/tests/test_extensions.py index 849f5d9..af8b11b 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -182,8 +182,7 @@ class ExtensionsTest(TestCase): analyse(self.senpy, input='nothing', algorithm='MOCK') assert False except Exception as ex: - assert 'generic exception on analysis' in ex['message'] - assert ex['status'] == 500 + assert 'generic exception on analysis' in str(ex) def test_filtering(self): """ Filtering plugins """