File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22Tools for managing result codes.
33"""
44
5+ import json
6+
57from requests import Response
68
79from vws .exceptions import (
1618 TargetStatusNotSuccess ,
1719 TargetStatusProcessing ,
1820 UnknownTarget ,
21+ UnknownVWSErrorPossiblyBadName ,
1922)
2023
2124
@@ -32,7 +35,12 @@ def raise_for_result_code(
3235 expected_result_code: See
3336 https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API.html#How-To-Interperete-VWS-API-Result-Codes
3437 """
35- result_code = response .json ()['result_code' ]
38+ try :
39+ result_code = response .json ()['result_code' ]
40+ except json .decoder .JSONDecodeError as exc :
41+ assert 'Oops' in response .text
42+ raise UnknownVWSErrorPossiblyBadName () from exc
43+
3644 if result_code == expected_result_code :
3745 return
3846
Original file line number Diff line number Diff line change 66from requests import Response
77
88
9+ class UnknownVWSErrorPossiblyBadName (Exception ):
10+ """
11+ Exception raised when VWS returns an HTML page which says "Oops, an error
12+ occurred".
13+
14+ THis has been seen to happen when the given name includes a bad character.
15+ """
16+
17+
918class ConnectionErrorPossiblyImageTooLarge (
1019 requests .exceptions .ConnectionError ,
1120):
Original file line number Diff line number Diff line change 2525 TargetStatusNotSuccess ,
2626 TargetStatusProcessing ,
2727 UnknownTarget ,
28+ UnknownVWSErrorPossiblyBadName ,
2829)
2930
3031
@@ -52,6 +53,17 @@ def test_invalid_given_id(vws_client: VWS) -> None:
5253 assert exc .value .response .status_code == codes .NOT_FOUND
5354
5455
56+ def test_add_bad_name (vws_client : VWS , high_quality_image : io .BytesIO ) -> None :
57+ """
58+ When a name with a bad character is given, an
59+ ``UnknownVWSErrorPossiblyBadName`` exception is raised.
60+ """
61+ max_char_value = 65535
62+ bad_name = chr (max_char_value + 1 )
63+ with pytest .raises (UnknownVWSErrorPossiblyBadName ):
64+ vws_client .add_target (name = bad_name , width = 1 , image = high_quality_image )
65+
66+
5567def test_request_quota_reached () -> None :
5668 """
5769 See https://github.com/adamtheturtle/vws-python/issues/822 for writing
You can’t perform that action at this time.
0 commit comments