@@ -97,7 +97,7 @@ namespace Aws
97
97
rhs.m_payload = Crt::Optional<Crt::ByteBuf>();
98
98
}
99
99
100
- Crt::List<EventStreamHeader> &MessageAmendment::GetHeaders () noexcept { return m_headers; }
100
+ Crt::List<EventStreamHeader> &MessageAmendment::GetHeaders () const noexcept { return m_headers; }
101
101
102
102
const Crt::Optional<Crt::ByteBuf> &MessageAmendment::GetPayload () const noexcept { return m_payload; }
103
103
@@ -213,10 +213,10 @@ namespace Aws
213
213
}
214
214
}
215
215
216
- bool ConnectionLifecycleHandler::OnErrorCallback (int errorCode )
216
+ bool ConnectionLifecycleHandler::OnErrorCallback (RpcError error )
217
217
{
218
- (void )errorCode ;
219
- /* Returning true implies that the connection will close upon receiving an error. */
218
+ (void )error ;
219
+ /* Returning true implies that the connection should close as a result of encountering this error. */
220
220
return true ;
221
221
}
222
222
@@ -230,7 +230,43 @@ namespace Aws
230
230
231
231
void ConnectionLifecycleHandler::OnConnectCallback () {}
232
232
233
- void ConnectionLifecycleHandler::OnDisconnectCallback (int errorCode) { (void )errorCode; }
233
+ void ConnectionLifecycleHandler::OnDisconnectCallback (RpcError error) { (void )error; }
234
+
235
+ Crt::String RpcError::StatusToString ()
236
+ {
237
+ switch (baseStatus)
238
+ {
239
+ case EVENT_STREAM_RPC_SUCCESS:
240
+ return " EVENT_STREAM_RPC_SUCCESS" ;
241
+ case EVENT_STREAM_RPC_NULL_PARAMETER:
242
+ return " EVENT_STREAM_RPC_NULL_PARAMETER" ;
243
+ case EVENT_STREAM_RPC_UNINITIALIZED:
244
+ return " EVENT_STREAM_RPC_UNINITIALIZED" ;
245
+ case EVENT_STREAM_RPC_ALLOCATION_ERROR:
246
+ return " EVENT_STREAM_RPC_ALLOCATION_ERROR" ;
247
+ case EVENT_STREAM_RPC_CONNECTION_SETUP_FAILED:
248
+ return " EVENT_STREAM_RPC_CONNECTION_SETUP_FAILED" ;
249
+ case EVENT_STREAM_RPC_CONNECTION_ACCESS_DENIED:
250
+ return " EVENT_STREAM_RPC_CONNECTION_ACCESS_DENIED" ;
251
+ case EVENT_STREAM_RPC_CONNECTION_ALREADY_ESTABLISHED:
252
+ return " EVENT_STREAM_RPC_CONNECTION_ALREADY_ESTABLISHED" ;
253
+ case EVENT_STREAM_RPC_CONNECTION_CLOSED:
254
+ return " EVENT_STREAM_RPC_CONNECTION_CLOSED" ;
255
+ case EVENT_STREAM_RPC_CONTINUATION_CLOSED:
256
+ return " EVENT_STREAM_RPC_CONTINUATION_CLOSED" ;
257
+ case EVENT_STREAM_RPC_UNKNOWN_PROTOCOL_MESSAGE:
258
+ return " EVENT_STREAM_RPC_UNKNOWN_PROTOCOL_MESSAGE" ;
259
+ case EVENT_STREAM_RPC_UNMAPPED_DATA:
260
+ return " EVENT_STREAM_RPC_UNMAPPED_DATA" ;
261
+ case EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE:
262
+ return " EVENT_STREAM_RPC_UNSUPPORTED_CONTENT_TYPE" ;
263
+ case EVENT_STREAM_RPC_CRT_ERROR:
264
+ Crt::String ret = " Failed with EVENT_STREAM_RPC_CRT_ERROR, the CRT error was " ;
265
+ ret += Crt::ErrorDebugString (crtError);
266
+ return ret;
267
+ }
268
+ return " Unknown status code" ;
269
+ }
234
270
235
271
std::future<RpcError> ClientConnection::Connect (
236
272
const ConnectionConfig &connectionConfig,
@@ -320,7 +356,7 @@ namespace Aws
320
356
AWS_LOGF_ERROR (
321
357
AWS_LS_EVENT_STREAM_RPC_CLIENT,
322
358
" A CRT error occurred while attempting to establish the connection: %s" ,
323
- aws_error_debug_str (crtError));
359
+ Crt::ErrorDebugString (crtError));
324
360
errorPromise.set_value ({EVENT_STREAM_RPC_CRT_ERROR, crtError});
325
361
return errorPromise.get_future ();
326
362
}
@@ -393,7 +429,7 @@ namespace Aws
393
429
AWS_LOGF_ERROR (
394
430
AWS_LS_EVENT_STREAM_RPC_CLIENT,
395
431
" A CRT error occurred while attempting to send a message: %s" ,
396
- aws_error_debug_str (errorCode));
432
+ Crt::ErrorDebugString (errorCode));
397
433
callbackData->onFlushPromise .set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
398
434
}
399
435
else
@@ -463,7 +499,7 @@ namespace Aws
463
499
AWS_LOGF_ERROR (
464
500
AWS_LS_EVENT_STREAM_RPC_CLIENT,
465
501
" A CRT error occurred while queueing a message to be sent on the connection: %s" ,
466
- aws_error_debug_str (errorCode));
502
+ Crt::ErrorDebugString (errorCode));
467
503
onFlushPromise.set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
468
504
Crt::Delete (callbackContainer, connection->m_allocator );
469
505
}
@@ -607,12 +643,12 @@ namespace Aws
607
643
AWS_LOGF_ERROR (
608
644
AWS_LS_EVENT_STREAM_RPC_CLIENT,
609
645
" A CRT error occurred while setting up the connection: %s" ,
610
- aws_error_debug_str (errorCode));
646
+ Crt::ErrorDebugString (errorCode));
611
647
thisConnection->m_connectAckedPromise .set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
612
648
aws_event_stream_rpc_client_connection_release (connection);
613
649
thisConnection->m_underlyingConnection = nullptr ;
614
650
/* No connection to close on error, so no need to check return value of the callback. */
615
- (void )thisConnection->m_lifecycleHandler ->OnErrorCallback (errorCode);
651
+ (void )thisConnection->m_lifecycleHandler ->OnErrorCallback ({EVENT_STREAM_RPC_CRT_ERROR, errorCode} );
616
652
}
617
653
else if (thisConnection->m_clientState == DISCONNECTING || thisConnection->m_clientState == DISCONNECTED)
618
654
{
@@ -687,7 +723,14 @@ namespace Aws
687
723
688
724
if (thisConnection->m_onConnectCalled )
689
725
{
690
- thisConnection->m_lifecycleHandler ->OnDisconnectCallback (errorCode);
726
+ if (errorCode)
727
+ {
728
+ thisConnection->m_lifecycleHandler ->OnDisconnectCallback ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
729
+ }
730
+ else
731
+ {
732
+ thisConnection->m_lifecycleHandler ->OnDisconnectCallback ({EVENT_STREAM_RPC_SUCCESS, 0 });
733
+ }
691
734
thisConnection->m_onConnectCalled = false ;
692
735
}
693
736
@@ -696,7 +739,7 @@ namespace Aws
696
739
AWS_LOGF_ERROR (
697
740
AWS_LS_EVENT_STREAM_RPC_CLIENT,
698
741
" A CRT error occurred while shutting down the connection: %s" ,
699
- aws_error_debug_str (errorCode));
742
+ Crt::ErrorDebugString (errorCode));
700
743
thisConnection->m_closedPromise .set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
701
744
}
702
745
else
@@ -770,7 +813,8 @@ namespace Aws
770
813
case AWS_EVENT_STREAM_RPC_MESSAGE_TYPE_PROTOCOL_ERROR:
771
814
case AWS_EVENT_STREAM_RPC_MESSAGE_TYPE_INTERNAL_ERROR:
772
815
773
- if (thisConnection->m_lifecycleHandler ->OnErrorCallback (AWS_ERROR_EVENT_STREAM_RPC_PROTOCOL_ERROR))
816
+ if (thisConnection->m_lifecycleHandler ->OnErrorCallback (
817
+ {EVENT_STREAM_RPC_CRT_ERROR, AWS_ERROR_EVENT_STREAM_RPC_PROTOCOL_ERROR}))
774
818
{
775
819
thisConnection->Close ();
776
820
}
@@ -780,7 +824,8 @@ namespace Aws
780
824
default :
781
825
return ;
782
826
783
- if (thisConnection->m_lifecycleHandler ->OnErrorCallback (EVENT_STREAM_RPC_UNKNOWN_PROTOCOL_MESSAGE))
827
+ if (thisConnection->m_lifecycleHandler ->OnErrorCallback (
828
+ {EVENT_STREAM_RPC_UNKNOWN_PROTOCOL_MESSAGE, 0 }))
784
829
{
785
830
thisConnection->Close ();
786
831
}
@@ -1022,7 +1067,7 @@ namespace Aws
1022
1067
AWS_LOGF_ERROR (
1023
1068
AWS_LS_EVENT_STREAM_RPC_CLIENT,
1024
1069
" A CRT error occurred while queueing a message to be sent on a stream: %s" ,
1025
- aws_error_debug_str (errorCode));
1070
+ Crt::ErrorDebugString (errorCode));
1026
1071
onFlushPromise.set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
1027
1072
Crt::Delete (callbackContainer, m_allocator);
1028
1073
}
@@ -1307,7 +1352,8 @@ namespace Aws
1307
1352
{
1308
1353
(void )operationError;
1309
1354
(void )rpcError;
1310
- /* Note: Always returning true forces the stream to close when an error occurs. */
1355
+ /* Note: Always returning true implies that the stream should close
1356
+ * as a result of encountering this error. */
1311
1357
return true ;
1312
1358
}
1313
1359
@@ -1523,7 +1569,7 @@ namespace Aws
1523
1569
AWS_LOGF_ERROR (
1524
1570
AWS_LS_EVENT_STREAM_RPC_CLIENT,
1525
1571
" A CRT error occurred while closing the stream: %s" ,
1526
- aws_error_debug_str (errorCode));
1572
+ Crt::ErrorDebugString (errorCode));
1527
1573
onTerminatePromise.set_value ({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
1528
1574
Crt::Delete (callbackContainer, m_allocator);
1529
1575
}
0 commit comments