Commit 4934afa1 authored by jan.koester's avatar jan.koester
Browse files

test

parent 4163cc43
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -1619,15 +1619,36 @@ namespace blogi {

        void _ensureMdbReady(int tid, const std::string &token = ""){
            if(!_mdb[tid]){
                try {
                    _mdb[tid] = std::make_unique<mediadb::Client>(_mdbUrl, false, true);
                } catch(std::exception &e) {
                    std::cerr << "media: _ensureMdbReady: new Client failed: " << e.what() << std::endl;
                    throw;
                }
            }
            if(!token.empty()){
                try {
                    _mdb[tid]->set_token(token);
                } catch(...) {
                } catch(std::exception &e) {
                    // Connection broken — recreate client and retry
                    std::cerr << "media: _ensureMdbReady: set_token failed, reconnecting: " << e.what() << std::endl;
                    try {
                        _mdb[tid] = std::make_unique<mediadb::Client>(_mdbUrl, false, true);
                        _mdb[tid]->set_token(token);
                    } catch(std::exception &e2) {
                        std::cerr << "media: _ensureMdbReady: reconnect failed: " << e2.what() << std::endl;
                        _mdb[tid].reset();
                        throw;
                    }
                } catch(...) {
                    std::cerr << "media: _ensureMdbReady: set_token unknown error, reconnecting" << std::endl;
                    try {
                        _mdb[tid] = std::make_unique<mediadb::Client>(_mdbUrl, false, true);
                        _mdb[tid]->set_token(token);
                    } catch(...) {
                        _mdb[tid].reset();
                        throw;
                    }
                }
            }
        }