@@ -86,20 +86,32 @@ public int hashCode() {
86
86
private final boolean retryable ;
87
87
private final String reason ;
88
88
private final boolean idempotent ;
89
+ private final String location ;
90
+ private final String debugInfo ;
89
91
90
92
public BaseServiceException (IOException exception , boolean idempotent ) {
91
93
super (message (exception ), exception );
94
+ int code = UNKNOWN_CODE ;
95
+ String reason = null ;
96
+ String location = null ;
97
+ String debugInfo = null ;
92
98
if (exception instanceof GoogleJsonResponseException ) {
93
- Error error = error (((GoogleJsonResponseException ) exception ).getDetails ());
94
- this .code = error .code ;
95
- this .reason = error .reason ;
96
- this .retryable = error .isRetryable (retryableErrors ());
97
- } else {
98
- this .code = UNKNOWN_CODE ;
99
- this .reason = null ;
100
- this .retryable = idempotent && isRetryable (exception );
99
+ GoogleJsonError jsonError = ((GoogleJsonResponseException ) exception ).getDetails ();
100
+ Error error = error (jsonError );
101
+ code = error .code ;
102
+ reason = error .reason ;
103
+ if (reason != null ) {
104
+ GoogleJsonError .ErrorInfo errorInfo = jsonError .getErrors ().get (0 );
105
+ location = errorInfo .getLocation ();
106
+ debugInfo = (String ) errorInfo .get ("debugInfo" );
107
+ }
101
108
}
109
+ this .code = code ;
110
+ this .retryable = idempotent && isRetryable (exception );
111
+ this .reason = reason ;
102
112
this .idempotent = idempotent ;
113
+ this .location = location ;
114
+ this .debugInfo = debugInfo ;
103
115
}
104
116
105
117
public BaseServiceException (GoogleJsonError error , boolean idempotent ) {
@@ -108,6 +120,8 @@ public BaseServiceException(GoogleJsonError error, boolean idempotent) {
108
120
this .reason = reason (error );
109
121
this .idempotent = idempotent ;
110
122
this .retryable = idempotent && isRetryable (error );
123
+ this .location = null ;
124
+ this .debugInfo = null ;
111
125
}
112
126
113
127
public BaseServiceException (int code , String message , String reason , boolean idempotent ) {
@@ -121,6 +135,8 @@ public BaseServiceException(int code, String message, String reason, boolean ide
121
135
this .reason = reason ;
122
136
this .idempotent = idempotent ;
123
137
this .retryable = idempotent && new Error (code , reason ).isRetryable (retryableErrors ());
138
+ this .location = null ;
139
+ this .debugInfo = null ;
124
140
}
125
141
126
142
protected Set <Error > retryableErrors () {
@@ -166,6 +182,18 @@ public boolean idempotent() {
166
182
return idempotent ;
167
183
}
168
184
185
+ /**
186
+ * Returns the service location where the error causing the exception occurred. Returns
187
+ * {@code null} if not set.
188
+ */
189
+ public String location () {
190
+ return location ;
191
+ }
192
+
193
+ protected String debugInfo () {
194
+ return debugInfo ;
195
+ }
196
+
169
197
protected static String reason (GoogleJsonError error ) {
170
198
if (error .getErrors () != null && !error .getErrors ().isEmpty ()) {
171
199
return error .getErrors ().get (0 ).getReason ();
0 commit comments