@@ -173,23 +173,6 @@ std::shared_ptr< ErrorDetails > ESCommunication::ParseErrorResponse(
173173 }
174174}
175175
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-
193176void ESCommunication::GetJsonSchema (ESResult& es_result) {
194177 // Prepare document and validate schema
195178 try {
@@ -232,15 +215,10 @@ ESCommunication::~ESCommunication() {
232215
233216std::string ESCommunication::GetErrorMessage () {
234217 // 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 ;
244222}
245223
246224ConnErrorType ESCommunication::GetErrorType () {
@@ -265,21 +243,18 @@ bool ESCommunication::ConnectDBStart() {
265243 LogMsg (ES_ALL, " Starting DB connection." );
266244 m_status = ConnStatusType::CONNECTION_BAD;
267245 if (!m_valid_connection_options) {
268- // TODO: get error message from CheckConnectionOptions
246+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
269247 m_error_message =
270248 " Invalid connection options, unable to connect to DB." ;
271- SetErrorDetails (" Invalid connection options" , m_error_message,
272- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
273249 LogMsg (ES_ERROR, m_error_message.c_str ());
274250 DropDBConnection ();
275251 return false ;
276252 }
277253
278254 m_status = ConnStatusType::CONNECTION_NEEDED;
279255 if (!EstablishConnection ()) {
256+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
280257 m_error_message = " Failed to establish connection to DB." ;
281- SetErrorDetails (" Connection error" , m_error_message,
282- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
283258 LogMsg (ES_ERROR, m_error_message.c_str ());
284259 DropDBConnection ();
285260 return false ;
@@ -312,21 +287,18 @@ bool ESCommunication::CheckConnectionOptions() {
312287 if (m_rt_opts.auth .auth_type == AUTHTYPE_BASIC) {
313288 if (m_rt_opts.auth .username .empty ()
314289 || m_rt_opts.auth .password .empty ()) {
290+ m_error_type = ConnErrorType::CONN_ERROR_INVALID_AUTH;
315291 m_error_message = AUTHTYPE_BASIC
316292 " authentication requires a username and password." ;
317- SetErrorDetails (" Auth error" , m_error_message,
318- ConnErrorType::CONN_ERROR_INVALID_AUTH);
319293 }
320294 } else {
295+ m_error_type = ConnErrorType::CONN_ERROR_INVALID_AUTH;
321296 m_error_message = " Unknown authentication type: '"
322297 + m_rt_opts.auth .auth_type + " '" ;
323- SetErrorDetails (" Auth error" , m_error_message,
324- ConnErrorType::CONN_ERROR_INVALID_AUTH);
325298 }
326299 } else if (m_rt_opts.conn .server == " " ) {
300+ m_error_type = ConnErrorType::CONN_ERROR_UNABLE_TO_ESTABLISH;
327301 m_error_message = " Host connection option was not specified." ;
328- SetErrorDetails (" Connection error" , m_error_message,
329- ConnErrorType::CONN_ERROR_UNABLE_TO_ESTABLISH);
330302 }
331303
332304 if (m_error_message != " " ) {
@@ -430,42 +402,36 @@ bool ESCommunication::IsSQLPluginInstalled(const std::string& plugin_response) {
430402 if (!plugin_name.compare (OPENDISTRO_SQL_PLUGIN_NAME)) {
431403 std::string sql_plugin_version =
432404 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 ());
436408 return true ;
437409 }
438410 } else {
411+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
439412 m_error_message =
440413 " Could not find all necessary fields in the plugin "
441414 " response object. "
442415 " (\" component\" , \" version\" )" ;
443- SetErrorDetails (" Connection error" , m_error_message,
444- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
445416 throw std::runtime_error (m_error_message.c_str ());
446417 }
447418 }
448419 } catch (const rabbit::type_mismatch& e) {
449420 m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
450421 m_error_message =
451422 " Error parsing endpoint response: " + std::string (e.what ());
452- SetErrorDetails (" Connection error" , m_error_message,
453- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
454423 } catch (const rabbit::parse_error& e) {
424+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
455425 m_error_message =
456426 " Error parsing endpoint response: " + std::string (e.what ());
457- SetErrorDetails (" Connection error" , m_error_message,
458- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
459427 } catch (const std::exception& e) {
428+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
460429 m_error_message =
461430 " Error parsing endpoint response: " + std::string (e.what ());
462- SetErrorDetails (" Connection error" , m_error_message,
463- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
464431 } catch (...) {
432+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
465433 m_error_message =
466434 " Unknown exception thrown when parsing plugin endpoint response." ;
467- SetErrorDetails (" Connection error" , m_error_message,
468- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
469435 }
470436
471437 LogMsg (ES_ERROR, m_error_message.c_str ());
@@ -486,35 +452,30 @@ bool ESCommunication::EstablishConnection() {
486452 IssueRequest (PLUGIN_ENDPOINT_FORMAT_JSON,
487453 Aws::Http::HttpMethod::HTTP_GET, " " , " " , " " );
488454 if (response == nullptr ) {
455+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
489456 m_error_message =
490457 " The SQL plugin must be installed in order to use this driver. "
491458 " Received NULL response." ;
492- SetErrorDetails (" HTTP client error" , m_error_message,
493- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
494459 } else {
495460 AwsHttpResponseToString (response, m_response_str);
496461 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 ())
498466 m_error_message += " Client error: '"
499467 + 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 ())
504469 m_error_message += " Response error: '" + m_response_str + " '." ;
505- SetErrorDetails (" Connection error" , m_error_message,
506- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
507- }
508470 } else {
509471 if (IsSQLPluginInstalled (m_response_str)) {
510472 return true ;
511473 } else {
474+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
512475 m_error_message =
513476 " The SQL plugin must be installed in order to use this "
514477 " driver. Response body: '"
515478 + m_response_str + " '" ;
516- SetErrorDetails (" Connection error" , m_error_message,
517- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
518479 }
519480 }
520481 }
@@ -544,11 +505,10 @@ std::vector< std::string > ESCommunication::GetColumnsWithSelectQuery(
544505
545506 // Validate response
546507 if (response == nullptr ) {
508+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
547509 m_error_message =
548510 " Failed to receive response from query. "
549511 " Received NULL response." ;
550- SetErrorDetails (" HTTP client error" , m_error_message,
551- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
552512 LogMsg (ES_ERROR, m_error_message.c_str ());
553513 return list_of_column;
554514 }
@@ -571,8 +531,6 @@ std::vector< std::string > ESCommunication::GetColumnsWithSelectQuery(
571531 m_error_message +=
572532 " Response error: '" + result->result_json + " '." ;
573533 }
574- SetErrorDetails (" Connection error" , m_error_message,
575- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
576534 LogMsg (ES_ERROR, m_error_message.c_str ());
577535 return list_of_column;
578536 }
@@ -592,15 +550,13 @@ std::vector< std::string > ESCommunication::GetColumnsWithSelectQuery(
592550int ESCommunication::ExecDirect (const char * query, const char * fetch_size_) {
593551 m_error_details.reset ();
594552 if (!query) {
553+ m_error_type = ConnErrorType::CONN_ERROR_INVALID_NULL_PTR;
595554 m_error_message = " Query is NULL" ;
596- SetErrorDetails (" Execution error" , m_error_message,
597- ConnErrorType::CONN_ERROR_INVALID_NULL_PTR);
598555 LogMsg (ES_ERROR, m_error_message.c_str ());
599556 return -1 ;
600557 } else if (!m_http_client) {
558+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
601559 m_error_message = " Unable to connect. Please try connecting again." ;
602- SetErrorDetails (" Execution error" , m_error_message,
603- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
604560 LogMsg (ES_ERROR, m_error_message.c_str ());
605561 return -1 ;
606562 }
@@ -618,11 +574,10 @@ int ESCommunication::ExecDirect(const char* query, const char* fetch_size_) {
618574
619575 // Validate response
620576 if (response == nullptr ) {
577+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
621578 m_error_message =
622579 " Failed to receive response from query. "
623580 " Received NULL response." ;
624- SetErrorDetails (" Execution error" , m_error_message,
625- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
626581 LogMsg (ES_ERROR, m_error_message.c_str ());
627582 return -1 ;
628583 }
@@ -654,13 +609,12 @@ int ESCommunication::ExecDirect(const char* query, const char* fetch_size_) {
654609 try {
655610 ConstructESResult (*result);
656611 } catch (std::runtime_error& e) {
612+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
657613 m_error_message =
658614 " Received runtime exception: " + std::string (e.what ());
659615 if (!result->result_json .empty ()) {
660616 m_error_message += " Result body: " + result->result_json ;
661617 }
662- SetErrorDetails (" Execution error" , m_error_message,
663- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
664618 LogMsg (ES_ERROR, m_error_message.c_str ());
665619 return -1 ;
666620 }
@@ -695,11 +649,10 @@ void ESCommunication::SendCursorQueries(std::string cursor) {
695649 SQL_ENDPOINT_FORMAT_JDBC, Aws::Http::HttpMethod::HTTP_POST,
696650 ctype, " " , " " , cursor);
697651 if (response == nullptr ) {
652+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
698653 m_error_message =
699654 " Failed to receive response from cursor. "
700655 " Received NULL response." ;
701- SetErrorDetails (" Cursor error" , m_error_message,
702- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
703656 LogMsg (ES_ERROR, m_error_message.c_str ());
704657 return ;
705658 }
@@ -725,10 +678,9 @@ void ESCommunication::SendCursorQueries(std::string cursor) {
725678 result.release ();
726679 }
727680 } catch (std::runtime_error& e) {
681+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
728682 m_error_message =
729683 " Received runtime exception: " + std::string (e.what ());
730- SetErrorDetails (" Cursor error" , m_error_message,
731- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
732684 LogMsg (ES_ERROR, m_error_message.c_str ());
733685 }
734686
@@ -744,11 +696,10 @@ void ESCommunication::SendCloseCursorRequest(const std::string& cursor) {
744696 IssueRequest (SQL_ENDPOINT_CLOSE_CURSOR,
745697 Aws::Http::HttpMethod::HTTP_POST, ctype, " " , " " , cursor);
746698 if (response == nullptr ) {
699+ m_error_type = ConnErrorType::CONN_ERROR_QUERY_SYNTAX;
747700 m_error_message =
748- " Failed to receive response from cursor close request . "
701+ " Failed to receive response from cursor. "
749702 " Received NULL response." ;
750- SetErrorDetails (" Cursor error" , m_error_message,
751- ConnErrorType::CONN_ERROR_QUERY_SYNTAX);
752703 LogMsg (ES_ERROR, m_error_message.c_str ());
753704 }
754705}
@@ -831,11 +782,10 @@ std::string ESCommunication::GetServerVersion() {
831782 std::shared_ptr< Aws::Http::HttpResponse > response =
832783 IssueRequest (" " , Aws::Http::HttpMethod::HTTP_GET, " " , " " , " " );
833784 if (response == nullptr ) {
785+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
834786 m_error_message =
835- " Failed to receive response from server version query. "
787+ " Failed to receive response from query. "
836788 " Received NULL response." ;
837- SetErrorDetails (" Connection error" , m_error_message,
838- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
839789 LogMsg (ES_ERROR, m_error_message.c_str ());
840790 return " " ;
841791 }
@@ -851,22 +801,19 @@ std::string ESCommunication::GetServerVersion() {
851801 }
852802
853803 } catch (const rabbit::type_mismatch& e) {
804+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
854805 m_error_message = " Error parsing main endpoint response: "
855806 + std::string (e.what ());
856- SetErrorDetails (" Connection error" , m_error_message,
857- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
858807 LogMsg (ES_ERROR, m_error_message.c_str ());
859808 } catch (const rabbit::parse_error& e) {
809+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
860810 m_error_message = " Error parsing main endpoint response: "
861811 + std::string (e.what ());
862- SetErrorDetails (" Connection error" , m_error_message,
863- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
864812 LogMsg (ES_ERROR, m_error_message.c_str ());
865813 } catch (const std::exception& e) {
814+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
866815 m_error_message = " Error parsing main endpoint response: "
867816 + std::string (e.what ());
868- SetErrorDetails (" Connection error" , m_error_message,
869- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
870817 LogMsg (ES_ERROR, m_error_message.c_str ());
871818 } catch (...) {
872819 LogMsg (ES_ERROR,
@@ -887,11 +834,10 @@ std::string ESCommunication::GetClusterName() {
887834 std::shared_ptr< Aws::Http::HttpResponse > response =
888835 IssueRequest (" " , Aws::Http::HttpMethod::HTTP_GET, " " , " " , " " );
889836 if (response == nullptr ) {
837+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
890838 m_error_message =
891- " Failed to receive response from cluster name query. "
839+ " Failed to receive response from query. "
892840 " Received NULL response." ;
893- SetErrorDetails (" Connection error" , m_error_message,
894- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
895841 LogMsg (ES_ERROR, m_error_message.c_str ());
896842 return " " ;
897843 }
@@ -907,22 +853,19 @@ std::string ESCommunication::GetClusterName() {
907853 }
908854
909855 } catch (const rabbit::type_mismatch& e) {
856+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
910857 m_error_message = " Error parsing main endpoint response: "
911858 + std::string (e.what ());
912- SetErrorDetails (" Connection error" , m_error_message,
913- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
914859 LogMsg (ES_ERROR, m_error_message.c_str ());
915860 } catch (const rabbit::parse_error& e) {
861+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
916862 m_error_message = " Error parsing main endpoint response: "
917863 + std::string (e.what ());
918- SetErrorDetails (" Connection error" , m_error_message,
919- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
920864 LogMsg (ES_ERROR, m_error_message.c_str ());
921865 } catch (const std::exception& e) {
866+ m_error_type = ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE;
922867 m_error_message = " Error parsing main endpoint response: "
923868 + std::string (e.what ());
924- SetErrorDetails (" Connection error" , m_error_message,
925- ConnErrorType::CONN_ERROR_COMM_LINK_FAILURE);
926869 LogMsg (ES_ERROR, m_error_message.c_str ());
927870 } catch (...) {
928871 LogMsg (ES_ERROR,
0 commit comments