14
14
15
15
"""Spanner DB API exceptions."""
16
16
17
+ from google .api_core .exceptions import GoogleAPICallError
18
+
17
19
18
20
class Warning (Exception ):
19
21
"""Important DB API warning."""
@@ -27,7 +29,49 @@ class Error(Exception):
27
29
Does not include :class:`Warning`.
28
30
"""
29
31
30
- pass
32
+ def _is_error_cause_instance_of_google_api_exception (self ):
33
+ return isinstance (self .__cause__ , GoogleAPICallError )
34
+
35
+ @property
36
+ def reason (self ):
37
+ """The reason of the error.
38
+ Reference:
39
+ https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L112
40
+ Returns:
41
+ Union[str, None]: An optional string containing reason of the error.
42
+ """
43
+ return self .__cause__ .reason if self ._is_error_cause_instance_of_google_api_exception () else None
44
+
45
+ @property
46
+ def domain (self ):
47
+ """The logical grouping to which the "reason" belongs.
48
+ Reference:
49
+ https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L112
50
+ Returns:
51
+ Union[str, None]: An optional string containing a logical grouping to which the "reason" belongs.
52
+ """
53
+ return self .__cause__ .domain if self ._is_error_cause_instance_of_google_api_exception () else None
54
+
55
+ @property
56
+ def metadata (self ):
57
+ """Additional structured details about this error.
58
+ Reference:
59
+ https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L112
60
+ Returns:
61
+ Union[Dict[str, str], None]: An optional object containing structured details about the error.
62
+ """
63
+ return self .__cause__ .metadata if self ._is_error_cause_instance_of_google_api_exception () else None
64
+
65
+ @property
66
+ def details (self ):
67
+ """Information contained in google.rpc.status.details.
68
+ Reference:
69
+ https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto
70
+ https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto
71
+ Returns:
72
+ Sequence[Any]: A list of structured objects from error_details.proto
73
+ """
74
+ return self .__cause__ .details if self ._is_error_cause_instance_of_google_api_exception () else None
31
75
32
76
33
77
class InterfaceError (Error ):
0 commit comments