@@ -71,6 +71,67 @@ static GglError release_client_subscriptions(uint32_t handle, size_t index) {
71
71
return ggl_ipc_release_subscriptions_for_conn (handle );
72
72
}
73
73
74
+ static void get_ipc_err_info (
75
+ GglIpcErrorCode error_code ,
76
+ GglBuffer * err_str ,
77
+ GglBuffer * service_model_type
78
+ ) {
79
+ switch (error_code ) {
80
+ case GGL_IPC_ERR_SERVICE_ERROR :
81
+ * err_str = GGL_STR ("ServiceError" );
82
+ * service_model_type = GGL_STR ("aws.greengrass#ServiceError" );
83
+ return ;
84
+
85
+ case GGL_IPC_ERR_RESOURCE_NOT_FOUND :
86
+ * err_str = GGL_STR ("ResourceNotFoundError" );
87
+ * service_model_type = GGL_STR ("aws.greengrass#ResourceNotFoundError" );
88
+ return ;
89
+
90
+ case GGL_IPC_ERR_INVALID_ARGUMENTS :
91
+ * err_str = GGL_STR ("InvalidArgumentsError" );
92
+ * service_model_type = GGL_STR ("aws.greengrass#InvalidArgumentsError" );
93
+ return ;
94
+
95
+ case GGL_IPC_ERR_COMPONENT_NOT_FOUND :
96
+ * err_str = GGL_STR ("ComponentNotFoundError" );
97
+ * service_model_type = GGL_STR ("aws.greengrass#ComponentNotFoundError" );
98
+ return ;
99
+
100
+ case GGL_IPC_ERR_UNAUTHORIZED_ERROR :
101
+ * err_str = GGL_STR ("UnauthorizedError" );
102
+ * service_model_type = GGL_STR ("aws.greengrass#UnauthorizedError" );
103
+ return ;
104
+
105
+ case GGL_IPC_ERR_CONFLICT_ERROR :
106
+ * err_str = GGL_STR ("ConflictError" );
107
+ * service_model_type = GGL_STR ("aws.greengrass#ConflictError" );
108
+ return ;
109
+
110
+ case GGL_IPC_ERR_FAILED_UPDATE_CONDITION_CHECK_ERROR :
111
+ * err_str = GGL_STR ("FailedUpdateConditionCheckError" );
112
+ * service_model_type
113
+ = GGL_STR ("aws.greengrass#FailedUpdateConditionCheckError" );
114
+ return ;
115
+
116
+ case GGL_IPC_ERR_INVALID_TOKEN_ERROR :
117
+ * err_str = GGL_STR ("InvalidTokenError" );
118
+ * service_model_type = GGL_STR ("aws.greengrass#InvalidTokenError" );
119
+ return ;
120
+
121
+ case GGL_IPC_ERR_INVALID_RECIPE_DIRECTORY_PATH_ERROR :
122
+ * err_str = GGL_STR ("InvalidRecipeDirectoryPathError" );
123
+ * service_model_type
124
+ = GGL_STR ("aws.greengrass#InvalidRecipeDirectoryPathError" );
125
+ return ;
126
+
127
+ case GGL_IPC_ERR_INVALID_ARTIFACTS_DIRECTORY_PATH_ERROR :
128
+ * err_str = GGL_STR ("InvalidArtifactsDirectoryPathError" );
129
+ * service_model_type
130
+ = GGL_STR ("aws.greengrass#InvalidArtifactsDirectoryPathError" );
131
+ return ;
132
+ }
133
+ }
134
+
74
135
static GglError deserialize_payload (GglBuffer payload , GglMap * out ) {
75
136
GglObject obj ;
76
137
@@ -253,26 +314,41 @@ static GglError handle_conn_init(
253
314
);
254
315
}
255
316
256
- static GglError send_stream_error (uint32_t handle , int32_t stream_id ) {
317
+ static GglError send_stream_error (
318
+ uint32_t handle , int32_t stream_id , GglIpcError ipc_error
319
+ ) {
257
320
GGL_LOGE ("Sending error on client %u stream %d." , handle , stream_id );
258
321
259
322
GGL_MTX_SCOPE_GUARD (& resp_array_mtx );
260
323
GglBuffer resp_buffer = GGL_BUF (resp_array );
261
324
325
+ GglBuffer service_model_type ;
326
+ GglBuffer error_code ;
327
+
328
+ get_ipc_err_info (ipc_error .error_code , & error_code , & service_model_type );
329
+
262
330
// TODO: Match classic error response
263
331
EventStreamHeader resp_headers [] = {
264
332
{ GGL_STR (":message-type" ),
265
333
{ EVENTSTREAM_INT32 , .int32 = EVENTSTREAM_APPLICATION_ERROR } },
266
334
{ GGL_STR (":message-flags" ),
267
335
{ EVENTSTREAM_INT32 , .int32 = EVENTSTREAM_TERMINATE_STREAM } },
268
336
{ GGL_STR (":stream-id" ), { EVENTSTREAM_INT32 , .int32 = stream_id } },
269
-
337
+ { GGL_STR (":content-json" ),
338
+ { EVENTSTREAM_STRING , .string = GGL_STR ("application/json" ) } },
339
+ { GGL_STR ("service-model-type" ),
340
+ { EVENTSTREAM_STRING , .string = service_model_type } },
270
341
};
271
- const size_t RESP_HEADERS_LEN
272
- = sizeof (resp_headers ) / sizeof (resp_headers [0 ]);
342
+ size_t resp_headers_len = sizeof (resp_headers ) / sizeof (resp_headers [0 ]);
273
343
274
344
GglError ret = eventstream_encode (
275
- & resp_buffer , resp_headers , RESP_HEADERS_LEN , GGL_NULL_READER
345
+ & resp_buffer ,
346
+ resp_headers ,
347
+ resp_headers_len ,
348
+ ggl_json_reader (& GGL_OBJ_MAP (GGL_MAP (
349
+ { GGL_STR ("_message" ), GGL_OBJ_BUF (ipc_error .message ) },
350
+ { GGL_STR ("_errorCode" ), GGL_OBJ_BUF (error_code ) }
351
+ )))
276
352
);
277
353
if (ret != GGL_ERR_OK ) {
278
354
return ret ;
@@ -284,7 +360,8 @@ static GglError send_stream_error(uint32_t handle, int32_t stream_id) {
284
360
static GglError handle_stream_operation (
285
361
uint32_t handle ,
286
362
EventStreamMessage * msg ,
287
- EventStreamCommonHeaders common_headers
363
+ EventStreamCommonHeaders common_headers ,
364
+ GglIpcError * ipc_error
288
365
) {
289
366
if (common_headers .message_type != EVENTSTREAM_APPLICATION_MESSAGE ) {
290
367
GGL_LOGE ("Client sent unhandled message type." );
@@ -326,7 +403,7 @@ static GglError handle_stream_operation(
326
403
}
327
404
328
405
return ggl_ipc_handle_operation (
329
- operation , payload_data , handle , common_headers .stream_id
406
+ operation , payload_data , handle , common_headers .stream_id , ipc_error
330
407
);
331
408
}
332
409
@@ -340,13 +417,16 @@ static GglError handle_operation(
340
417
return GGL_ERR_INVALID ;
341
418
}
342
419
343
- GglError ret = handle_stream_operation (handle , msg , common_headers );
420
+ GglIpcError ipc_error = { 0 };
421
+
422
+ GglError ret
423
+ = handle_stream_operation (handle , msg , common_headers , & ipc_error );
344
424
if (ret == GGL_ERR_FATAL ) {
345
425
return GGL_ERR_FAILURE ;
346
426
}
347
427
348
428
if (ret != GGL_ERR_OK ) {
349
- return send_stream_error (handle , common_headers .stream_id );
429
+ return send_stream_error (handle , common_headers .stream_id , ipc_error );
350
430
}
351
431
352
432
return GGL_ERR_OK ;
0 commit comments