Browse Source

Specialize documentation exceptions, Closes #9

Bastien Sevajol 7 years ago
parent
commit
8d95059f63
2 changed files with 17 additions and 6 deletions
  1. 5 6
      hapic/doc.py
  2. 12 0
      hapic/exception.py

+ 5 - 6
hapic/doc.py View File

@@ -9,10 +9,11 @@ from apispec.ext.marshmallow.swagger import schema2jsonschema
9 9
 
10 10
 from hapic.decorator import DecoratedController
11 11
 from hapic.decorator import DECORATION_ATTRIBUTE_NAME
12
-
13
-# Bottle regular expression to locate url parameters
14 12
 from hapic.description import ControllerDescription
13
+from hapic.exception import NoRoutesException
14
+from hapic.exception import RouteNotFound
15 15
 
16
+# Bottle regular expression to locate url parameters
16 17
 BOTTLE_RE_PATH_URL = re.compile(r'<(?:[^:<>]+:)?([^<>]+)>')
17 18
 
18 19
 
@@ -21,8 +22,7 @@ def find_bottle_route(
21 22
     app: bottle.Bottle,
22 23
 ):
23 24
     if not app.routes:
24
-        # TODO BS 20171010: specialize exception, see #9
25
-        raise Exception('There is no routes in yout bottle app')
25
+        raise NoRoutesException('There is no routes in yout bottle app')
26 26
 
27 27
     reference = decorated_controller.reference
28 28
     for route in app.routes:
@@ -38,9 +38,8 @@ def find_bottle_route(
38 38
 
39 39
         if match_with_wrapper or match_with_wrapped or match_with_token:
40 40
             return route
41
-    # TODO BS 20171010: specialize exception, see #9
42 41
     # TODO BS 20171010: Raise exception or print error ? see #10
43
-    raise Exception(
42
+    raise RouteNotFound(
44 43
         'Decorated route "{}" was not found in bottle routes'.format(
45 44
             decorated_controller.name,
46 45
         )

+ 12 - 0
hapic/exception.py View File

@@ -35,3 +35,15 @@ class InputValidationException(InputWorkflowException, ProcessException):
35 35
 
36 36
 class OutputValidationException(InputWorkflowException, ProcessException):
37 37
     pass
38
+
39
+
40
+class DocumentationException(HapicException):
41
+    pass
42
+
43
+
44
+class NoRoutesException(DocumentationException):
45
+    pass
46
+
47
+
48
+class RouteNotFound(DocumentationException):
49
+    pass