14
14
#include < algorithm>
15
15
#include < iostream>
16
16
17
- /* TODO: Change to constexpr */
18
- #define EVENTSTREAM_VERSION_HEADER " :version"
19
- #define EVENTSTREAM_VERSION_STRING " 0.1.0"
20
- #define CONTENT_TYPE_HEADER " :content-type"
21
- #define CONTENT_TYPE_APPLICATION_TEXT " text/plain"
22
- #define CONTENT_TYPE_APPLICATION_JSON " application/json"
23
- #define SERVICE_MODEL_TYPE_HEADER " service-model-type"
17
+ constexpr auto EVENTSTREAM_VERSION_HEADER = " :version" ;
18
+ constexpr auto EVENTSTREAM_VERSION_STRING = " 0.1.0" ;
19
+ constexpr auto CONTENT_TYPE_HEADER = " :content-type" ;
20
+ constexpr auto CONTENT_TYPE_APPLICATION_JSON = " application/json" ;
21
+ constexpr auto SERVICE_MODEL_TYPE_HEADER = " service-model-type" ;
24
22
25
23
namespace Aws
26
24
{
@@ -320,6 +318,10 @@ namespace Aws
320
318
if (crtError)
321
319
{
322
320
std::promise<RpcError> errorPromise;
321
+ AWS_LOGF_ERROR (
322
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
323
+ " A CRT error occurred while attempting to establish the connection: %s" ,
324
+ aws_error_debug_str (crtError));
323
325
errorPromise.set_value ({EVENT_STREAM_RPC_CRT_ERROR, crtError});
324
326
return errorPromise.get_future ();
325
327
}
@@ -389,6 +391,10 @@ namespace Aws
389
391
390
392
if (errorCode)
391
393
{
394
+ AWS_LOGF_ERROR (
395
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
396
+ " A CRT error occurred while attempting to send a message: %s" ,
397
+ aws_error_debug_str (errorCode));
392
398
callbackData->onFlushPromise .set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
393
399
}
394
400
else
@@ -455,6 +461,10 @@ namespace Aws
455
461
if (errorCode)
456
462
{
457
463
onFlushPromise = std::move (callbackContainer->onFlushPromise );
464
+ AWS_LOGF_ERROR (
465
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
466
+ " A CRT error occurred while queueing a message to be sent on the connection: %s" ,
467
+ aws_error_debug_str (errorCode));
458
468
onFlushPromise.set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
459
469
Crt::Delete (callbackContainer, connection->m_allocator );
460
470
}
@@ -595,6 +605,10 @@ namespace Aws
595
605
if (errorCode)
596
606
{
597
607
thisConnection->m_clientState = DISCONNECTED;
608
+ AWS_LOGF_ERROR (
609
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
610
+ " A CRT error occurred while setting up the connection: %s" ,
611
+ aws_error_debug_str (errorCode));
598
612
thisConnection->m_connectAckedPromise .set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
599
613
aws_event_stream_rpc_client_connection_release (connection);
600
614
thisConnection->m_underlyingConnection = nullptr ;
@@ -679,9 +693,17 @@ namespace Aws
679
693
}
680
694
681
695
if (errorCode)
696
+ {
697
+ AWS_LOGF_ERROR (
698
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
699
+ " A CRT error occurred while shutting down the connection: %s" ,
700
+ aws_error_debug_str (errorCode));
682
701
thisConnection->m_closedPromise .set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
702
+ }
683
703
else
704
+ {
684
705
thisConnection->m_closedPromise .set_value ({EVENT_STREAM_RPC_SUCCESS, errorCode});
706
+ }
685
707
}
686
708
687
709
void ClientConnection::s_onProtocolMessage (
@@ -999,6 +1021,10 @@ namespace Aws
999
1021
if (errorCode)
1000
1022
{
1001
1023
onFlushPromise = std::move (callbackContainer->onFlushPromise );
1024
+ AWS_LOGF_ERROR (
1025
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
1026
+ " A CRT error occurred while queueing a message to be sent on a stream: %s" ,
1027
+ aws_error_debug_str (errorCode));
1002
1028
onFlushPromise.set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
1003
1029
Crt::Delete (callbackContainer, m_allocator);
1004
1030
}
@@ -1129,40 +1155,16 @@ namespace Aws
1129
1155
rhs.m_rpcError = {EVENT_STREAM_RPC_UNINITIALIZED, 0 };
1130
1156
}
1131
1157
1132
- TaggedResult::operator bool () const noexcept
1133
- {
1134
- if (m_responseType == OPERATION_RESPONSE)
1135
- {
1136
- return true ;
1137
- }
1138
- else
1139
- {
1140
- return false ;
1141
- }
1142
- }
1158
+ TaggedResult::operator bool () const noexcept { return m_responseType == OPERATION_RESPONSE; }
1143
1159
1144
1160
AbstractShapeBase *TaggedResult::GetOperationResponse () const noexcept
1145
1161
{
1146
- if (m_responseType == OPERATION_RESPONSE)
1147
- {
1148
- return m_operationResult.m_response .get ();
1149
- }
1150
- else
1151
- {
1152
- return nullptr ;
1153
- }
1162
+ return (m_responseType == OPERATION_RESPONSE) ? m_operationResult.m_response .get () : nullptr ;
1154
1163
}
1155
1164
1156
1165
OperationError *TaggedResult::GetOperationError () const noexcept
1157
1166
{
1158
- if (m_responseType == OPERATION_ERROR)
1159
- {
1160
- return m_operationResult.m_error .get ();
1161
- }
1162
- else
1163
- {
1164
- return nullptr ;
1165
- }
1167
+ return (m_responseType == OPERATION_ERROR) ? m_operationResult.m_error .get () : nullptr ;
1166
1168
}
1167
1169
1168
1170
RpcError TaggedResult::GetRpcError () const noexcept
@@ -1185,6 +1187,7 @@ namespace Aws
1185
1187
1186
1188
if (m_clientContinuation.IsClosed () && !m_resultReceived)
1187
1189
{
1190
+ AWS_LOGF_ERROR (AWS_LS_EVENT_STREAM_RPC_CLIENT, " The underlying stream is already closed." );
1188
1191
m_initialResponsePromise.set_value (TaggedResult ({EVENT_STREAM_RPC_CONNECTION_CLOSED, 0 }));
1189
1192
m_resultReceived = true ;
1190
1193
}
@@ -1230,7 +1233,7 @@ namespace Aws
1230
1233
1231
1234
if (response.get () == nullptr )
1232
1235
{
1233
- /* TODO: Log an error */
1236
+ AWS_LOGF_ERROR (AWS_LS_EVENT_STREAM_RPC_CLIENT, " Failed to allocate a response from the payload. " );
1234
1237
return EVENT_STREAM_RPC_ALLOCATION_ERROR;
1235
1238
}
1236
1239
@@ -1301,7 +1304,7 @@ namespace Aws
1301
1304
{
1302
1305
(void )operationError;
1303
1306
(void )rpcError;
1304
- /* Always returning true forces the stream to close when an error occurs. */
1307
+ /* Note: Always returning true forces the stream to close when an error occurs. */
1305
1308
return true ;
1306
1309
}
1307
1310
@@ -1333,6 +1336,10 @@ namespace Aws
1333
1336
if (modelHeader == nullptr )
1334
1337
{
1335
1338
/* Missing required service model type header. */
1339
+ AWS_LOGF_ERROR (
1340
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
1341
+ " A required header (%s) could not be found in the message." ,
1342
+ SERVICE_MODEL_TYPE_HEADER);
1336
1343
errorCode = EVENT_STREAM_RPC_UNMAPPED_DATA;
1337
1344
}
1338
1345
@@ -1344,12 +1351,18 @@ namespace Aws
1344
1351
{
1345
1352
if (m_messageCount == 1 && m_operationModelContext.GetInitialResponseModelName () != modelName)
1346
1353
{
1354
+ AWS_LOGF_ERROR (
1355
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
1356
+ " The model name of the initial response did not match its expected model name." );
1347
1357
errorCode = EVENT_STREAM_RPC_UNMAPPED_DATA;
1348
1358
}
1349
1359
else if (
1350
1360
m_messageCount > 1 && m_operationModelContext.GetStreamingResponseModelName ().has_value () &&
1351
1361
m_operationModelContext.GetStreamingResponseModelName ().value () != modelName)
1352
1362
{
1363
+ AWS_LOGF_ERROR (
1364
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
1365
+ " The model name of a subsequent response did not match its expected model name." );
1353
1366
errorCode = EVENT_STREAM_RPC_UNMAPPED_DATA;
1354
1367
}
1355
1368
}
@@ -1361,12 +1374,21 @@ namespace Aws
1361
1374
contentHeader = GetHeaderByName (headers, Crt::String (CONTENT_TYPE_HEADER));
1362
1375
if (contentHeader == nullptr )
1363
1376
{
1364
- /* TODO: Log an error. */
1365
1377
/* Missing required content type header. */
1366
- errorCode = EVENT_STREAM_RPC_UNMAPPED_DATA;
1378
+ AWS_LOGF_ERROR (
1379
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
1380
+ " A required header (%s) could not be found in the message." ,
1381
+ CONTENT_TYPE_HEADER);
1382
+ errorCode = EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE;
1367
1383
}
1368
1384
else if (contentHeader->GetValueAsString (contentType) && contentType != CONTENT_TYPE_APPLICATION_JSON)
1369
1385
{
1386
+ /* Missing required content type header. */
1387
+ AWS_LOGF_ERROR (
1388
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
1389
+ " The content type (%s) header was specified with an unsupported value (%s)." ,
1390
+ CONTENT_TYPE_HEADER,
1391
+ contentType.c_str ());
1370
1392
errorCode = EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE;
1371
1393
}
1372
1394
}
@@ -1498,6 +1520,11 @@ namespace Aws
1498
1520
if (errorCode)
1499
1521
{
1500
1522
onTerminatePromise = std::move (callbackContainer->onFlushPromise );
1523
+ std::promise<RpcError> errorPromise;
1524
+ AWS_LOGF_ERROR (
1525
+ AWS_LS_EVENT_STREAM_RPC_CLIENT,
1526
+ " A CRT error occurred while closing the stream: %s" ,
1527
+ aws_error_debug_str (errorCode));
1501
1528
onTerminatePromise.set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
1502
1529
Crt::Delete (callbackContainer, m_allocator);
1503
1530
}
0 commit comments