Skip to content

Commit d72f73c

Browse files
author
Frédéric Guillot
committed
Add specific exception
1 parent 19a293c commit d72f73c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

tests/test_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import unittest
2020

2121
from ubersmith_remote_module_server.api import Api
22+
from ubersmith_remote_module_server.exceptions import RemoteModuleException
2223

2324

2425
class ApiTest(unittest.TestCase):
@@ -69,7 +70,7 @@ def test_execute_method_returns_string(self):
6970
assert_that(output.status_code, is_(200))
7071

7172
def test_execute_method_raise_an_exception(self):
72-
self.router.invoke_method.side_effect = Exception('Some Error')
73+
self.router.invoke_method.side_effect = RemoteModuleException('Some Error')
7374
output = self.api_client.post(self.generate_module_path('module2'),
7475
headers={'Content-Type': 'application/json'},
7576
data=json.dumps(

ubersmith_remote_module_server/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import logging
1818

1919
from flask import request, current_app
20+
from ubersmith_remote_module_server.exceptions import RemoteModuleException
2021

2122

2223
class Api(object):
@@ -44,7 +45,8 @@ def handle_remote_invocation(self, module):
4445
try:
4546
output = self.router.invoke_method(module=module, **data)
4647
return json_response(output, 200)
47-
except Exception as e:
48+
except RemoteModuleException as e:
49+
logging.exception(e)
4850
return json_response(str(e), 500)
4951

5052

ubersmith_remote_module_server/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ class NamedArgumentsOnly(Exception):
2323
def __init__(self, msg="UbersmithCore was called with non-named arguments, "
2424
"you MUST use named arguments (kwargs)"):
2525
super(NamedArgumentsOnly, self).__init__(msg)
26+
27+
28+
class RemoteModuleException(Exception):
29+
pass

0 commit comments

Comments
 (0)