@@ -173,23 +173,6 @@ std::shared_ptr< ErrorDetails > ESCommunication::ParseErrorResponse(
173
173
}
174
174
}
175
175
176
- void ESCommunication::SetErrorDetails (std::string reason, std::string message,
177
- ConnErrorType error_type) {
178
- // Prepare document and validate schema
179
- auto error_details = std::make_shared< ErrorDetails >();
180
- error_details->reason = reason;
181
- error_details->details = message;
182
- error_details->source_type = " Dummy type" ;
183
- error_details->type = error_type;
184
- m_error_details = error_details;
185
- }
186
-
187
- void ESCommunication::SetErrorDetails (ErrorDetails details) {
188
- // Prepare document and validate schema
189
- auto error_details = std::make_shared< ErrorDetails >(details);
190
- m_error_details = error_details;
191
- }
192
-
193
176
void ESCommunication::GetJsonSchema (ESResult& es_result) {
194
177
// Prepare document and validate schema
195
178
try {
@@ -232,15 +215,10 @@ ESCommunication::~ESCommunication() {
232
215
233
216
std::string ESCommunication::GetErrorMessage () {
234
217
// TODO #35 - Check if they expect NULL or "" when there is no error.
235
- if (m_error_details) {
236
- m_error_details->details = std::regex_replace (
237
- m_error_details->details , std::regex (" \\ n" ), " \\\\ n" );
238
- return ERROR_MSG_PREFIX + m_error_details->reason + " : "
239
- + m_error_details->details ;
240
- } else {
241
- return ERROR_MSG_PREFIX
242
- + " No error details available; check the driver logs." ;
243
- }
218
+ m_error_details->details = std::regex_replace (m_error_details->details ,
219
+ std::regex (" \\ n" ), " \\\\ n" );
220
+ return ERROR_MSG_PREFIX + m_error_details->reason + " : "
221
+ + m_error_details->details ;
244
222
}
245
223
246
224
ConnErrorType ESCommunication::GetErrorType () {
@@ -265,21 +243,18 @@ bool ESCommunication::ConnectDBStart() {
265
243
LogMsg (ES_ALL, " Starting DB connection." );
266
244
m_status = ConnStatusType::CONNECTION_BAD;
267
245
if (!m_valid_connection_options) {
268
- // TODO: get error message from CheckConnectionOptions
246
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
269
247
m_error_message =
270
248
" Invalid connection options, unable to connect to DB." ;
271
- SetErrorDetails (" Invalid connection options" , m_error_message,
272
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
273
249
LogMsg (ES_ERROR, m_error_message.c_str ());
274
250
DropDBConnection ();
275
251
return false ;
276
252
}
277
253
278
254
m_status = ConnStatusType::CONNECTION_NEEDED;
279
255
if (!EstablishConnection ()) {
256
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
280
257
m_error_message = " Failed to establish connection to DB." ;
281
- SetErrorDetails (" Connection error" , m_error_message,
282
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
283
258
LogMsg (ES_ERROR, m_error_message.c_str ());
284
259
DropDBConnection ();
285
260
return false ;
@@ -312,21 +287,18 @@ bool ESCommunication::CheckConnectionOptions() {
312
287
if (m_rt_opts.auth .auth_type == AUTHTYPE_BASIC) {
313
288
if (m_rt_opts.auth .username .empty ()
314
289
|| m_rt_opts.auth .password .empty ()) {
290
+ m_error_type = ConnErrorType::CONN_ERROR_INVALID_AUTH;
315
291
m_error_message = AUTHTYPE_BASIC
316
292
" authentication requires a username and password." ;
317
- SetErrorDetails (" Auth error" , m_error_message,
318
- ConnErrorType::CONN_ERROR_INVALID_AUTH);
319
293
}
320
294
} else {
295
+ m_error_type = ConnErrorType::CONN_ERROR_INVALID_AUTH;
321
296
m_error_message = " Unknown authentication type: '"
322
297
+ m_rt_opts.auth .auth_type + " '" ;
323
- SetErrorDetails (" Auth error" , m_error_message,
324
- ConnErrorType::CONN_ERROR_INVALID_AUTH);
325
298
}
326
299
} else if (m_rt_opts.conn .server == " " ) {
300
+ m_error_type = ConnErrorType::CONN_ERROR_UNABLE_TO_ESTABLISH;
327
301
m_error_message = " Host connection option was not specified." ;
328
- SetErrorDetails (" Connection error" , m_error_message,
329
- ConnErrorType::CONN_ERROR_UNABLE_TO_ESTABLISH);
330
302
}
331
303
332
304
if (m_error_message != " " ) {
@@ -430,42 +402,36 @@ bool ESCommunication::IsSQLPluginInstalled(const std::string& plugin_response) {
430
402
if (!plugin_name.compare (OPENDISTRO_SQL_PLUGIN_NAME)) {
431
403
std::string sql_plugin_version =
432
404
it.at (" version" ).as_string ();
433
- LogMsg (ES_INFO , std::string (" Found SQL plugin version '"
434
- + sql_plugin_version + " '." )
435
- .c_str ());
405
+ LogMsg (ES_ERROR , std::string (" Found SQL plugin version '"
406
+ + sql_plugin_version + " '." )
407
+ .c_str ());
436
408
return true ;
437
409
}
438
410
} else {
411
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
439
412
m_error_message =
440
413
" Could not find all necessary fields in the plugin "
441
414
" response object. "
442
415
" (\" component\" , \" version\" )" ;
443
- SetErrorDetails (" Connection error" , m_error_message,
444
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
445
416
throw std::runtime_error (m_error_message.c_str ());
446
417
}
447
418
}
448
419
} catch (const rabbit::type_mismatch& e) {
449
420
m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
450
421
m_error_message =
451
422
" Error parsing endpoint response: " + std::string (e.what ());
452
- SetErrorDetails (" Connection error" , m_error_message,
453
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
454
423
} catch (const rabbit::parse_error& e) {
424
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
455
425
m_error_message =
456
426
" Error parsing endpoint response: " + std::string (e.what ());
457
- SetErrorDetails (" Connection error" , m_error_message,
458
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
459
427
} catch (const std::exception & e) {
428
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
460
429
m_error_message =
461
430
" Error parsing endpoint response: " + std::string (e.what ());
462
- SetErrorDetails (" Connection error" , m_error_message,
463
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
464
431
} catch (...) {
432
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
465
433
m_error_message =
466
434
" Unknown exception thrown when parsing plugin endpoint response." ;
467
- SetErrorDetails (" Connection error" , m_error_message,
468
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
469
435
}
470
436
471
437
LogMsg (ES_ERROR, m_error_message.c_str ());
@@ -486,35 +452,30 @@ bool ESCommunication::EstablishConnection() {
486
452
IssueRequest (PLUGIN_ENDPOINT_FORMAT_JSON,
487
453
Aws::Http::HttpMethod::HTTP_GET, " " , " " , " " );
488
454
if (response == nullptr ) {
455
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
489
456
m_error_message =
490
457
" The SQL plugin must be installed in order to use this driver. "
491
458
" Received NULL response." ;
492
- SetErrorDetails (" HTTP client error" , m_error_message,
493
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
494
459
} else {
495
460
AwsHttpResponseToString (response, m_response_str);
496
461
if (response->GetResponseCode () != Aws::Http::HttpResponseCode::OK) {
497
- if (response->HasClientError ()) {
462
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
463
+ m_error_message =
464
+ " The SQL plugin must be installed in order to use this driver." ;
465
+ if (response->HasClientError ())
498
466
m_error_message += " Client error: '"
499
467
+ response->GetClientErrorMessage () + " '." ;
500
- SetErrorDetails (" HTTP client error" , m_error_message,
501
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
502
- }
503
- if (!m_response_str.empty ()) {
468
+ if (!m_response_str.empty ())
504
469
m_error_message += " Response error: '" + m_response_str + " '." ;
505
- SetErrorDetails (" Connection error" , m_error_message,
506
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
507
- }
508
470
} else {
509
471
if (IsSQLPluginInstalled (m_response_str)) {
510
472
return true ;
511
473
} else {
474
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
512
475
m_error_message =
513
476
" The SQL plugin must be installed in order to use this "
514
477
" driver. Response body: '"
515
478
+ m_response_str + " '" ;
516
- SetErrorDetails (" Connection error" , m_error_message,
517
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
518
479
}
519
480
}
520
481
}
@@ -544,11 +505,10 @@ std::vector< std::string > ESCommunication::GetColumnsWithSelectQuery(
544
505
545
506
// Validate response
546
507
if (response == nullptr ) {
508
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
547
509
m_error_message =
548
510
" Failed to receive response from query. "
549
511
" Received NULL response." ;
550
- SetErrorDetails (" HTTP client error" , m_error_message,
551
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
552
512
LogMsg (ES_ERROR, m_error_message.c_str ());
553
513
return list_of_column;
554
514
}
@@ -571,8 +531,6 @@ std::vector< std::string > ESCommunication::GetColumnsWithSelectQuery(
571
531
m_error_message +=
572
532
" Response error: '" + result->result_json + " '." ;
573
533
}
574
- SetErrorDetails (" Connection error" , m_error_message,
575
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
576
534
LogMsg (ES_ERROR, m_error_message.c_str ());
577
535
return list_of_column;
578
536
}
@@ -592,15 +550,13 @@ std::vector< std::string > ESCommunication::GetColumnsWithSelectQuery(
592
550
int ESCommunication::ExecDirect (const char * query, const char * fetch_size_) {
593
551
m_error_details.reset ();
594
552
if (!query) {
553
+ m_error_type = ConnErrorType::CONN_ERROR_INVALID_NULL_PTR;
595
554
m_error_message = " Query is NULL" ;
596
- SetErrorDetails (" Execution error" , m_error_message,
597
- ConnErrorType::CONN_ERROR_INVALID_NULL_PTR);
598
555
LogMsg (ES_ERROR, m_error_message.c_str ());
599
556
return -1 ;
600
557
} else if (!m_http_client) {
558
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
601
559
m_error_message = " Unable to connect. Please try connecting again." ;
602
- SetErrorDetails (" Execution error" , m_error_message,
603
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
604
560
LogMsg (ES_ERROR, m_error_message.c_str ());
605
561
return -1 ;
606
562
}
@@ -618,11 +574,10 @@ int ESCommunication::ExecDirect(const char* query, const char* fetch_size_) {
618
574
619
575
// Validate response
620
576
if (response == nullptr ) {
577
+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
621
578
m_error_message =
622
579
" Failed to receive response from query. "
623
580
" Received NULL response." ;
624
- SetErrorDetails (" Execution error" , m_error_message,
625
- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
626
581
LogMsg (ES_ERROR, m_error_message.c_str ());
627
582
return -1 ;
628
583
}
@@ -654,13 +609,12 @@ int ESCommunication::ExecDirect(const char* query, const char* fetch_size_) {
654
609
try {
655
610
ConstructESResult (*result);
656
611
} catch (std::runtime_error& e) {
612
+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
657
613
m_error_message =
658
614
" Received runtime exception: " + std::string (e.what ());
659
615
if (!result->result_json .empty ()) {
660
616
m_error_message += " Result body: " + result->result_json ;
661
617
}
662
- SetErrorDetails (" Execution error" , m_error_message,
663
- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
664
618
LogMsg (ES_ERROR, m_error_message.c_str ());
665
619
return -1 ;
666
620
}
@@ -695,11 +649,10 @@ void ESCommunication::SendCursorQueries(std::string cursor) {
695
649
SQL_ENDPOINT_FORMAT_JDBC, Aws::Http::HttpMethod::HTTP_POST,
696
650
ctype, " " , " " , cursor);
697
651
if (response == nullptr ) {
652
+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
698
653
m_error_message =
699
654
" Failed to receive response from cursor. "
700
655
" Received NULL response." ;
701
- SetErrorDetails (" Cursor error" , m_error_message,
702
- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
703
656
LogMsg (ES_ERROR, m_error_message.c_str ());
704
657
return ;
705
658
}
@@ -725,10 +678,9 @@ void ESCommunication::SendCursorQueries(std::string cursor) {
725
678
result.release ();
726
679
}
727
680
} catch (std::runtime_error& e) {
681
+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
728
682
m_error_message =
729
683
" Received runtime exception: " + std::string (e.what ());
730
- SetErrorDetails (" Cursor error" , m_error_message,
731
- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
732
684
LogMsg (ES_ERROR, m_error_message.c_str ());
733
685
}
734
686
@@ -744,11 +696,10 @@ void ESCommunication::SendCloseCursorRequest(const std::string& cursor) {
744
696
IssueRequest (SQL_ENDPOINT_CLOSE_CURSOR,
745
697
Aws::Http::HttpMethod::HTTP_POST, ctype, " " , " " , cursor);
746
698
if (response == nullptr ) {
699
+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
747
700
m_error_message =
748
- " Failed to receive response from cursor close request . "
701
+ " Failed to receive response from cursor. "
749
702
" Received NULL response." ;
750
- SetErrorDetails (" Cursor error" , m_error_message,
751
- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
752
703
LogMsg (ES_ERROR, m_error_message.c_str ());
753
704
}
754
705
}
@@ -831,11 +782,10 @@ std::string ESCommunication::GetServerVersion() {
831
782
std::shared_ptr< Aws::Http::HttpResponse > response =
832
783
IssueRequest (" " , Aws::Http::HttpMethod::HTTP_GET, " " , " " , " " );
833
784
if (response == nullptr ) {
785
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
834
786
m_error_message =
835
- " Failed to receive response from server version query. "
787
+ " Failed to receive response from query. "
836
788
" Received NULL response." ;
837
- SetErrorDetails (" Connection error" , m_error_message,
838
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
839
789
LogMsg (ES_ERROR, m_error_message.c_str ());
840
790
return " " ;
841
791
}
@@ -851,22 +801,19 @@ std::string ESCommunication::GetServerVersion() {
851
801
}
852
802
853
803
} catch (const rabbit::type_mismatch& e) {
804
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
854
805
m_error_message = " Error parsing main endpoint response: "
855
806
+ std::string (e.what ());
856
- SetErrorDetails (" Connection error" , m_error_message,
857
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
858
807
LogMsg (ES_ERROR, m_error_message.c_str ());
859
808
} catch (const rabbit::parse_error& e) {
809
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
860
810
m_error_message = " Error parsing main endpoint response: "
861
811
+ std::string (e.what ());
862
- SetErrorDetails (" Connection error" , m_error_message,
863
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
864
812
LogMsg (ES_ERROR, m_error_message.c_str ());
865
813
} catch (const std::exception & e) {
814
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
866
815
m_error_message = " Error parsing main endpoint response: "
867
816
+ std::string (e.what ());
868
- SetErrorDetails (" Connection error" , m_error_message,
869
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
870
817
LogMsg (ES_ERROR, m_error_message.c_str ());
871
818
} catch (...) {
872
819
LogMsg (ES_ERROR,
@@ -887,11 +834,10 @@ std::string ESCommunication::GetClusterName() {
887
834
std::shared_ptr< Aws::Http::HttpResponse > response =
888
835
IssueRequest (" " , Aws::Http::HttpMethod::HTTP_GET, " " , " " , " " );
889
836
if (response == nullptr ) {
837
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
890
838
m_error_message =
891
- " Failed to receive response from cluster name query. "
839
+ " Failed to receive response from query. "
892
840
" Received NULL response." ;
893
- SetErrorDetails (" Connection error" , m_error_message,
894
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
895
841
LogMsg (ES_ERROR, m_error_message.c_str ());
896
842
return " " ;
897
843
}
@@ -907,22 +853,19 @@ std::string ESCommunication::GetClusterName() {
907
853
}
908
854
909
855
} catch (const rabbit::type_mismatch& e) {
856
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
910
857
m_error_message = " Error parsing main endpoint response: "
911
858
+ std::string (e.what ());
912
- SetErrorDetails (" Connection error" , m_error_message,
913
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
914
859
LogMsg (ES_ERROR, m_error_message.c_str ());
915
860
} catch (const rabbit::parse_error& e) {
861
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
916
862
m_error_message = " Error parsing main endpoint response: "
917
863
+ std::string (e.what ());
918
- SetErrorDetails (" Connection error" , m_error_message,
919
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
920
864
LogMsg (ES_ERROR, m_error_message.c_str ());
921
865
} catch (const std::exception & e) {
866
+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
922
867
m_error_message = " Error parsing main endpoint response: "
923
868
+ std::string (e.what ());
924
- SetErrorDetails (" Connection error" , m_error_message,
925
- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
926
869
LogMsg (ES_ERROR, m_error_message.c_str ());
927
870
} catch (...) {
928
871
LogMsg (ES_ERROR,
0 commit comments