Skip to content

Commit

Permalink
Add specific exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Guillot committed Mar 14, 2017
1 parent 19a293c commit d72f73c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import unittest

from ubersmith_remote_module_server.api import Api
from ubersmith_remote_module_server.exceptions import RemoteModuleException


class ApiTest(unittest.TestCase):
Expand Down Expand Up @@ -69,7 +70,7 @@ def test_execute_method_returns_string(self):
assert_that(output.status_code, is_(200))

def test_execute_method_raise_an_exception(self):
self.router.invoke_method.side_effect = Exception('Some Error')
self.router.invoke_method.side_effect = RemoteModuleException('Some Error')
output = self.api_client.post(self.generate_module_path('module2'),
headers={'Content-Type': 'application/json'},
data=json.dumps(
Expand Down
4 changes: 3 additions & 1 deletion ubersmith_remote_module_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import logging

from flask import request, current_app
from ubersmith_remote_module_server.exceptions import RemoteModuleException


class Api(object):
Expand Down Expand Up @@ -44,7 +45,8 @@ def handle_remote_invocation(self, module):
try:
output = self.router.invoke_method(module=module, **data)
return json_response(output, 200)
except Exception as e:
except RemoteModuleException as e:
logging.exception(e)
return json_response(str(e), 500)


Expand Down
4 changes: 4 additions & 0 deletions ubersmith_remote_module_server/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ class NamedArgumentsOnly(Exception):
def __init__(self, msg="UbersmithCore was called with non-named arguments, "
"you MUST use named arguments (kwargs)"):
super(NamedArgumentsOnly, self).__init__(msg)


class RemoteModuleException(Exception):
pass

0 comments on commit d72f73c

Please sign in to comment.