|
14 | 14 | from timeout_decorator import timeout |
15 | 15 |
|
16 | 16 | from vws._authorization import authorization_header, rfc_1123_date |
17 | | -from vws.exceptions import ( |
18 | | - AuthenticationFailure, |
19 | | - BadImage, |
20 | | - Fail, |
21 | | - ImageTooLarge, |
22 | | - MetadataTooLarge, |
23 | | - ProjectInactive, |
24 | | - TargetNameExist, |
25 | | - TargetProcessingTimeout, |
26 | | - TargetStatusNotSuccess, |
27 | | - TargetStatusProcessing, |
28 | | - UnknownTarget, |
29 | | -) |
| 17 | +from vws._result_codes import raise_for_result_code |
| 18 | +from vws.exceptions import TargetProcessingTimeout |
30 | 19 |
|
31 | 20 |
|
32 | 21 | def _target_api_request( |
@@ -86,39 +75,6 @@ def _target_api_request( |
86 | 75 | return response |
87 | 76 |
|
88 | 77 |
|
89 | | -def _raise_for_result_code( |
90 | | - response: Response, |
91 | | - expected_result_code: str, |
92 | | -) -> None: |
93 | | - """ |
94 | | - Raise an appropriate exception if the expected result code for a successful |
95 | | - request is not returned. |
96 | | -
|
97 | | - Args: |
98 | | - response: A response from Vuforia. |
99 | | - expected_result_code: See |
100 | | - https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API.html#How-To-Interperete-VWS-API-Result-Codes |
101 | | - """ |
102 | | - result_code = response.json()['result_code'] |
103 | | - if result_code == expected_result_code: |
104 | | - return |
105 | | - |
106 | | - exception = { |
107 | | - 'AuthenticationFailure': AuthenticationFailure, |
108 | | - 'BadImage': BadImage, |
109 | | - 'Fail': Fail, |
110 | | - 'ImageTooLarge': ImageTooLarge, |
111 | | - 'MetadataTooLarge': MetadataTooLarge, |
112 | | - 'ProjectInactive': ProjectInactive, |
113 | | - 'TargetNameExist': TargetNameExist, |
114 | | - 'TargetStatusProcessing': TargetStatusProcessing, |
115 | | - 'TargetStatusNotSuccess': TargetStatusNotSuccess, |
116 | | - 'UnknownTarget': UnknownTarget, |
117 | | - }[result_code] |
118 | | - |
119 | | - raise exception(response=response) |
120 | | - |
121 | | - |
122 | 78 | class VWS: |
123 | 79 | """ |
124 | 80 | An interface to Vuforia Web Services APIs. |
@@ -173,7 +129,7 @@ def _make_request( |
173 | 129 | base_vws_url=self._base_vws_url, |
174 | 130 | ) |
175 | 131 |
|
176 | | - _raise_for_result_code( |
| 132 | + raise_for_result_code( |
177 | 133 | response=response, |
178 | 134 | expected_result_code=expected_result_code, |
179 | 135 | ) |
|
0 commit comments