55from functools import partial , wraps
66from typing import Any , Callable
77
8- import boto .exception
98from botocore .exceptions import ClientError
109
1110
@@ -140,17 +139,6 @@ def match_equals(regex, string, values):
140139 return matched [0 ] in values
141140
142141
143- def is_swf_response_error (error ):
144- """
145- Return true if *error* is a :class:`SWFResponseError` exception.
146-
147- :param error: is the exception to check.
148- :type error: Exception.
149-
150- """
151- return isinstance (error , boto .exception .SWFResponseError )
152-
153-
154142def is_unknown_resource_raised (error , * args , ** kwargs ):
155143 """
156144 Handler that checks if *error* is an unknown resource fault.
@@ -159,7 +147,7 @@ def is_unknown_resource_raised(error, *args, **kwargs):
159147 :type error: Exception
160148
161149 """
162- if not isinstance (error , ( boto . exception . SWFResponseError , ClientError ) ):
150+ if not isinstance (error , ClientError ):
163151 return False
164152
165153 return extract_error_code (error ) == "UnknownResourceFault"
@@ -241,77 +229,6 @@ def raises(exception, when, extract: Callable[[Any], str] = str):
241229
242230 :param when: predicate to apply.
243231 :type when: (error, *args, **kwargs) -> bool
244-
245- Examples
246- --------
247-
248- Let's build a :class:`boto.swf.exceptions.SWFResponseError` for an unknown
249- execution:
250-
251- FIXME commented-out these doctests for now as they fail on python3
252- (returning simpleflow.swf.mapper.exceptions.DoesNotExistError and such, not just DoesNotExistError)
253- # >>> status = 400
254- # >>> reason = 'Bad Request'
255- # >>> body_type = 'com.amazonaws.swf.base.model#UnknownResourceFault'
256- # >>> body_message = 'Unknown execution: blah'
257- # >>> body = {'__type': body_type, 'message': body_message}
258- # >>> error_code = 'UnknownResourceFault'
259- # >>> from boto.swf.exceptions import SWFResponseError
260- # >>> err = SWFResponseError(status, reason, body, error_code)
261- # >>> raises(DoesNotExistError,
262- # ... when=is_unknown_resource_raised,
263- # ... extract=extract_resource)(err)
264- # Traceback (most recent call last):
265- # ...
266- # DoesNotExistError: Resource execution does not exist
267- #
268- # >>> body = {'__type': body_type}
269- # >>> err = SWFResponseError(status, reason, body, error_code)
270- # >>> raises(DoesNotExistError,
271- # ... when=is_unknown_resource_raised,
272- # ... extract=extract_resource)(err)
273- # Traceback (most recent call last):
274- # ...
275- # DoesNotExistError: Resource unknown does not exist
276- #
277- # Now, we do the same for an unknown domain:
278- #
279- # >>> body_message = 'Unknown domain'
280- # >>> body = {'__type': body_type, 'message': body_message}
281- # >>> err = SWFResponseError(status, reason, body, error_code)
282- # >>> raises(DoesNotExistError,
283- # ... when=is_unknown_resource_raised,
284- # ... extract=extract_resource)(err)
285- # Traceback (most recent call last):
286- # ...
287- # DoesNotExistError: Resource domain does not exist
288- #
289- # If it does not detect an error related to an unknown resource,
290- # it raises a :class:`ResponseError`:
291- #
292- # >>> body_message = 'Other Fault'
293- # >>> body = {'__type': body_type, 'message': body_message}
294- # >>> err = SWFResponseError(status, reason, body, error_code)
295- # >>> err.error_code = 'OtherFault'
296- # >>> raises(DoesNotExistError,
297- # ... when=is_unknown_resource_raised,
298- # ... extract=extract_resource)(err)
299- # ... # doctest: +IGNORE_EXCEPTION_DETAIL
300- # Traceback (most recent call last):
301- # ...
302- # SWFResponseError: SWFResponseError: 400 Bad Request
303- # {'message': 'Other Fault', '__type': 'com.amazonaws.swf.base.model#UnknownResourceFault'}
304- #
305- # If it's not a :class:`boto.swf.exceptions.SWFResponseError`, it
306- # raises the exception as-is:
307- #
308- # >>> raises(DoesNotExistError,
309- # ... when=is_unknown_resource_raised,
310- # ... extract=extract_resource)(Exception('boom!'))
311- # Traceback (most recent call last):
312- # ...
313- # Exception: boom!
314-
315232 """
316233
317234 @wraps (raises )
0 commit comments