Browse Source

Specialize documentation exceptions, Closes #9

Bastien Sevajol 6 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
 
9
 
10
 from hapic.decorator import DecoratedController
10
 from hapic.decorator import DecoratedController
11
 from hapic.decorator import DECORATION_ATTRIBUTE_NAME
11
 from hapic.decorator import DECORATION_ATTRIBUTE_NAME
12
-
13
-# Bottle regular expression to locate url parameters
14
 from hapic.description import ControllerDescription
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
 BOTTLE_RE_PATH_URL = re.compile(r'<(?:[^:<>]+:)?([^<>]+)>')
17
 BOTTLE_RE_PATH_URL = re.compile(r'<(?:[^:<>]+:)?([^<>]+)>')
17
 
18
 
18
 
19
 
21
     app: bottle.Bottle,
22
     app: bottle.Bottle,
22
 ):
23
 ):
23
     if not app.routes:
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
     reference = decorated_controller.reference
27
     reference = decorated_controller.reference
28
     for route in app.routes:
28
     for route in app.routes:
38
 
38
 
39
         if match_with_wrapper or match_with_wrapped or match_with_token:
39
         if match_with_wrapper or match_with_wrapped or match_with_token:
40
             return route
40
             return route
41
-    # TODO BS 20171010: specialize exception, see #9
42
     # TODO BS 20171010: Raise exception or print error ? see #10
41
     # TODO BS 20171010: Raise exception or print error ? see #10
43
-    raise Exception(
42
+    raise RouteNotFound(
44
         'Decorated route "{}" was not found in bottle routes'.format(
43
         'Decorated route "{}" was not found in bottle routes'.format(
45
             decorated_controller.name,
44
             decorated_controller.name,
46
         )
45
         )

+ 12 - 0
hapic/exception.py View File

35
 
35
 
36
 class OutputValidationException(InputWorkflowException, ProcessException):
36
 class OutputValidationException(InputWorkflowException, ProcessException):
37
     pass
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