Skip to content

Commit 2a9d6a6

Browse files
Merge pull request #1292 from VWS-Python/conn-error-test
Move exceptions around a little, separating the VWS Exceptions from the custom exceptions
2 parents 08913ab + 9968143 commit 2a9d6a6

14 files changed

+592
-454
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Changelog
66
Next
77
----
88

9+
* Breaking change: Move exceptions and create base exceptions.
10+
It is now possible to, for example, catch
11+
``vws.exceptions.base_exceptions.VWSException`` to catch many of the
12+
exceptions raised by the ``VWS`` client.
13+
Credit to ``@laymonage`` for this change.
14+
915
2020.08.21.0
1016
------------
1117

docs/source/exceptions.rst

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
Exceptions
22
==========
33

4-
.. automodule:: vws.exceptions
4+
.. contents::
5+
6+
Base exceptions
7+
---------------
8+
9+
.. automodule:: vws.exceptions.base_exceptions
10+
:members:
11+
:show-inheritance:
12+
:inherited-members: Exception
13+
:exclude-members: errno, filename, filename2, strerror
14+
15+
VWS exceptions
16+
--------------
17+
18+
.. automodule:: vws.exceptions.vws_exceptions
19+
:members:
20+
:show-inheritance:
21+
:inherited-members: Exception
22+
:exclude-members: errno, filename, filename2, strerror
23+
24+
CloudRecoService exceptions
25+
---------------------------
26+
27+
.. automodule:: vws.exceptions.cloud_reco_exceptions
28+
:members:
29+
:show-inheritance:
30+
:inherited-members: Exception
31+
:exclude-members: errno, filename, filename2, strerror
32+
33+
Custom exceptions
34+
-----------------
35+
36+
.. automodule:: vws.exceptions.custom_exceptions
537
:members:
638
:show-inheritance:
739
:inherited-members: Exception

src/vws/_result_codes.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/vws/exceptions/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Custom exceptions raised by this package.
3+
"""

src/vws/exceptions/base_exceptions.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Base exceptions for errors returned by Vuforia Web Services or the Vuforia
3+
Cloud Recognition Web API.
4+
"""
5+
6+
from requests import Response
7+
8+
9+
class CloudRecoException(Exception):
10+
"""
11+
Base class for Vuforia Cloud Recognition Web API exceptions.
12+
"""
13+
14+
def __init__(self, response: Response) -> None:
15+
"""
16+
Args:
17+
response: The response to a request to Vuforia.
18+
"""
19+
super().__init__(response.text)
20+
self._response = response
21+
22+
@property
23+
def response(self) -> Response:
24+
"""
25+
The response returned by Vuforia which included this error.
26+
"""
27+
return self._response
28+
29+
30+
class VWSException(Exception):
31+
"""
32+
Base class for Vuforia Web Services errors.
33+
34+
These errors are defined at
35+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Interperete-VWS-API-Result-Codes.
36+
"""
37+
38+
def __init__(self, response: Response) -> None:
39+
"""
40+
Args:
41+
response: The response to a request to Vuforia.
42+
"""
43+
super().__init__()
44+
self._response = response
45+
46+
@property
47+
def response(self) -> Response:
48+
"""
49+
The response returned by Vuforia which included this error.
50+
"""
51+
return self._response
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Exceptions which match errors raised by the Vuforia Cloud Recognition Web APIs.
3+
"""
4+
5+
6+
from vws.exceptions.base_exceptions import CloudRecoException
7+
8+
9+
class MatchProcessing(CloudRecoException):
10+
"""
11+
Exception raised when a query is made with an image which matches a target
12+
which is processing or has recently been deleted.
13+
"""
14+
15+
16+
class MaxNumResultsOutOfRange(CloudRecoException):
17+
"""
18+
Exception raised when the ``max_num_results`` given to the Cloud
19+
Recognition Web API query endpoint is out of range.
20+
"""
21+
22+
23+
class InactiveProject(CloudRecoException):
24+
"""
25+
Exception raised when Vuforia returns a response with a result code
26+
'InactiveProject'.
27+
"""
28+
29+
30+
class BadImage(CloudRecoException):
31+
"""
32+
Exception raised when Vuforia returns a response with a result code
33+
'BadImage'.
34+
"""
35+
36+
37+
class AuthenticationFailure(CloudRecoException):
38+
"""
39+
Exception raised when Vuforia returns a response with a result code
40+
'AuthenticationFailure'.
41+
"""
42+
43+
44+
class RequestTimeTooSkewed(CloudRecoException):
45+
"""
46+
Exception raised when Vuforia returns a response with a result code
47+
'RequestTimeTooSkewed'.
48+
"""
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Exceptions which do not map to errors at
3+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Interperete-VWS-API-Result-Codes
4+
or simple errors given by the cloud recognition service.
5+
"""
6+
7+
import requests
8+
9+
10+
class UnknownVWSErrorPossiblyBadName(Exception):
11+
"""
12+
Exception raised when VWS returns an HTML page which says "Oops, an error
13+
occurred".
14+
15+
This has been seen to happen when the given name includes a bad character.
16+
"""
17+
18+
19+
class ConnectionErrorPossiblyImageTooLarge(requests.ConnectionError):
20+
"""
21+
Exception raised when a ConnectionError is raised from a query. This has
22+
been seen to happen when the given image is too large.
23+
"""
24+
25+
26+
class TargetProcessingTimeout(Exception):
27+
"""
28+
Exception raised when waiting for a target to be processed times out.
29+
"""

0 commit comments

Comments
 (0)