Skip to content

Commit

Permalink
Merge branch 'fix-missing-operation-id' into bad-operation-id-to-5xx
Browse files Browse the repository at this point in the history
  • Loading branch information
jfinkhaeuser committed Sep 7, 2016
2 parents d755859 + 6697dc3 commit 70d9d9d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion connexion/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ def add_paths(self, paths=None):
if self.resolver_error_handler is not None:
self._add_resolver_error_handler(method, path, err)
else:
self._handle_add_operation_error(path, method, sys.exc_info())
exc_info = err.exc_info
if exc_info is None:
exc_info = sys.exc_info()
self._handle_add_operation_error(path, method, exc_info)
except Exception:
# All other relevant exceptions should be handled as well.
self._handle_add_operation_error(path, method, sys.exc_info())
Expand Down
6 changes: 5 additions & 1 deletion connexion/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ class ConnexionException(Exception):


class ResolverError(LookupError):
def __init__(self, reason='Unknown reason'):
def __init__(self, reason='Unknown reason', exc_info=None):
"""
:param reason: Reason why the resolver failed.
:type reason: str
:param exc_info: If specified, gives details of the original exception
as returned by sys.exc_info()
:type exc_info: tuple | None
"""
self.reason = reason
self.exc_info = exc_info

def __str__(self): # pragma: no cover
return '<ResolverError: {}>'.format(self.reason)
Expand Down
8 changes: 6 additions & 2 deletions connexion/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ def resolve_function_from_operation_id(self, operation_id):
:type operation_id: str
"""
msg = 'Cannot resolve operationId "%s"!' % (operation_id,)
try:
return self.function_resolver(operation_id)
except (ImportError, AttributeError, ValueError):
raise ResolverError('Cannot resolve operationId "%s"!' % (operation_id,))
except ImportError:
import sys
raise ResolverError(msg, sys.exc_info())
except (AttributeError, ValueError):
raise ResolverError(msg)


class RestyResolver(Resolver):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_template():


def test_invalid_operation_does_stop_application_to_setup():
with pytest.raises(ResolverError):
with pytest.raises(ImportError):
Api(TEST_FOLDER / "fakeapi/op_error_api.yaml", "/api/v1.0",
{'title': 'OK'})
with pytest.raises(ResolverError):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ max-line-length=120
exclude=connexion/__init__.py

[tox]
envlist=pypy,py27,py34,py35,py35-flask0.10.1,isort-check,flake8
envlist=py27,py34

[tox:travis]
pypy=pypy
Expand Down

0 comments on commit 70d9d9d

Please sign in to comment.