@@ -106,6 +106,26 @@ impl NaocsGrpcResponse {
106
106
request_id : None ,
107
107
}
108
108
}
109
+ pub const fn not_found ( ) -> Self {
110
+ Self {
111
+ result_code : 500 ,
112
+ error_code : Some ( 300 ) ,
113
+ message : None ,
114
+ request_id : None ,
115
+ }
116
+ }
117
+ pub const fn unregister ( ) -> Self {
118
+ Self {
119
+ result_code : 500 ,
120
+ error_code : Some ( 301 ) ,
121
+ message : None ,
122
+ request_id : None ,
123
+ }
124
+ }
125
+ }
126
+
127
+ impl AsPayload for NaocsGrpcResponse {
128
+ const TYPE_NAME : & ' static str = "Response" ;
109
129
}
110
130
111
131
#[ derive( Clone , Debug , Serialize , Deserialize ) ]
@@ -170,6 +190,24 @@ pub struct ConfigQueryResponse {
170
190
pub response : NaocsGrpcResponse ,
171
191
}
172
192
193
+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
194
+ pub struct ConfigQueryResponseNotFound {
195
+ #[ serde( flatten) ]
196
+ pub response : NaocsGrpcResponse ,
197
+ }
198
+
199
+ impl Default for ConfigQueryResponseNotFound {
200
+ fn default ( ) -> Self {
201
+ ConfigQueryResponseNotFound {
202
+ response : NaocsGrpcResponse :: not_found ( ) ,
203
+ }
204
+ }
205
+ }
206
+
207
+ impl AsPayload for ConfigQueryResponseNotFound {
208
+ const TYPE_NAME : & ' static str = "ConfigQueryResponse" ;
209
+ }
210
+
173
211
impl From < ConfigItem > for ConfigQueryResponse {
174
212
fn from ( item : ConfigItem ) -> Self {
175
213
Self {
@@ -238,16 +276,20 @@ pub async fn dispatch_request(type_info: &str, value: &str, access_token: Option
238
276
"ServerCheckRequest" => ServerCheckResponse :: success ( None ) . as_payload ( ) ,
239
277
"HealthCheckRequest" => HealthCheckResponse :: success ( ) . as_payload ( ) ,
240
278
"ConfigQueryRequest" => {
241
- let ctx = get_ctx. await ?;
279
+ let Ok ( ctx) = get_ctx. await else {
280
+ return Ok ( NaocsGrpcResponse :: unregister ( ) . as_payload ( ) )
281
+ } ;
242
282
let ConfigQueryRequest { data_id, group, tenant } = serde_json:: from_str ( value) . map_err ( |_e| TardisError :: bad_request ( "expect a ConfigQueryRequest" , "" ) ) ?;
243
283
let mut descriptor = ConfigDescriptor {
244
284
namespace_id : tenant. unwrap_or ( "public" . into ( ) ) ,
245
285
data_id,
246
286
group,
247
287
..Default :: default ( )
248
288
} ;
249
- let result: ConfigQueryResponse = get_config_detail ( & mut descriptor, & funs, & ctx) . await ?. into ( ) ;
250
- result. as_payload ( )
289
+ match get_config_detail ( & mut descriptor, & funs, & ctx) . await {
290
+ Ok ( data) => ConfigQueryResponse :: from ( data) . as_payload ( ) ,
291
+ Err ( _) => ConfigQueryResponseNotFound :: default ( ) . as_payload ( ) ,
292
+ }
251
293
}
252
294
"ConfigBatchListenRequest" => {
253
295
let ctx = get_ctx. await ?;
0 commit comments