@@ -35,8 +35,9 @@ CouchbaseErrorType CouchbaseClient::getErrorType(const std::error_code& error_co
3535}
3636
3737nonstd::expected<::couchbase::collection, CouchbaseErrorType> CouchbaseClient::getCollection (const CouchbaseCollection& collection) {
38- if (auto error_type = establishConnection ()) {
39- return nonstd::make_unexpected (*error_type);
38+ auto connection_result = establishConnection ();
39+ if (!connection_result) {
40+ return nonstd::make_unexpected (connection_result.error ());
4041 }
4142 return cluster_->bucket (collection.bucket_name ).scope (collection.scope_name ).collection (collection.collection_name );
4243}
@@ -88,19 +89,19 @@ void CouchbaseClient::close() {
8889 }
8990}
9091
91- std::optional< CouchbaseErrorType> CouchbaseClient::establishConnection () {
92+ nonstd::expected< void , CouchbaseErrorType> CouchbaseClient::establishConnection () {
9293 if (cluster_) {
93- return std:: nullopt ;
94+ return {} ;
9495 }
9596
9697 auto options = ::couchbase::cluster_options (username_, password_);
9798 auto [connect_err, cluster] = ::couchbase::cluster::connect (connection_string_, options).get ();
9899 if (connect_err.ec ()) {
99100 logger_->log_error (" Failed to connect to Couchbase cluster with error code: '{}' and message: '{}'" , connect_err.ec (), connect_err.message ());
100- return getErrorType (connect_err.ec ());
101+ return nonstd::make_unexpected ( getErrorType (connect_err.ec () ));
101102 }
102103 cluster_ = std::move (cluster);
103- return std:: nullopt ;
104+ return {} ;
104105}
105106
106107namespace controllers {
@@ -121,8 +122,9 @@ void CouchbaseClusterService::onEnable() {
121122 }
122123
123124 client_ = std::make_unique<CouchbaseClient>(connection_string, username, password, logger_);
124- if (auto result = client_->establishConnection ()) {
125- if (result == CouchbaseErrorType::FATAL) {
125+ auto result = client_->establishConnection ();
126+ if (!result) {
127+ if (result.error () == CouchbaseErrorType::FATAL) {
126128 throw minifi::Exception (ExceptionType::PROCESS_SCHEDULE_EXCEPTION, " Failed to connect to Couchbase cluster with fatal error" );
127129 }
128130 logger_->log_warn (" Failed to connect to Couchbase cluster with temporary error, will retry connection when a Couchbase processor is triggered" );
0 commit comments