@@ -40,8 +40,9 @@ public abstract static class ResourceNotFoundException extends SpannerException
40
40
@ Nullable String message ,
41
41
ResourceInfo resourceInfo ,
42
42
@ Nullable Throwable cause ,
43
- @ Nullable ApiException apiException ) {
44
- super (token , ErrorCode .NOT_FOUND , /* retryable */ false , message , cause , apiException );
43
+ @ Nullable ApiException apiException ,
44
+ @ Nullable XGoogSpannerRequestId reqId ) {
45
+ super (token , ErrorCode .NOT_FOUND , /* retryable */ false , message , cause , apiException , reqId );
45
46
this .resourceInfo = resourceInfo ;
46
47
}
47
48
@@ -56,6 +57,7 @@ public String getResourceName() {
56
57
57
58
private final ErrorCode code ;
58
59
private final ApiException apiException ;
60
+ private final XGoogSpannerRequestId requestId ;
59
61
60
62
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
61
63
SpannerException (
@@ -75,19 +77,39 @@ public String getResourceName() {
75
77
@ Nullable String message ,
76
78
@ Nullable Throwable cause ,
77
79
@ Nullable ApiException apiException ) {
80
+ this (token , code , retryable , message , cause , apiException , null );
81
+ }
82
+
83
+ /** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
84
+ SpannerException (
85
+ DoNotConstructDirectly token ,
86
+ ErrorCode code ,
87
+ boolean retryable ,
88
+ @ Nullable String message ,
89
+ @ Nullable Throwable cause ,
90
+ @ Nullable ApiException apiException ,
91
+ @ Nullable XGoogSpannerRequestId requestId ) {
78
92
super (message , cause , code .getCode (), retryable );
79
93
if (token != DoNotConstructDirectly .ALLOWED ) {
80
94
throw new AssertionError ("Do not construct directly: use SpannerExceptionFactory" );
81
95
}
82
96
this .code = Preconditions .checkNotNull (code );
83
97
this .apiException = apiException ;
98
+ this .requestId = requestId ;
84
99
}
85
100
86
101
/** Returns the error code associated with this exception. */
87
102
public ErrorCode getErrorCode () {
88
103
return code ;
89
104
}
90
105
106
+ public String getRequestId () {
107
+ if (requestId == null ) {
108
+ return "" ;
109
+ }
110
+ return requestId .toString ();
111
+ }
112
+
91
113
enum DoNotConstructDirectly {
92
114
ALLOWED
93
115
}
0 commit comments