]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
reduce exception handling
authorn0tlu5 <darfisultoni@gmail.com>
Fri, 24 May 2024 06:35:04 +0000 (13:35 +0700)
committern0tlu5 <darfisultoni@gmail.com>
Fri, 24 May 2024 06:35:04 +0000 (13:35 +0700)
pdns/lua-record.cc

index cf95e0ea35c03650b34e8840288a1b38bb703e5a..0a0f5dbad0bbcdadb5219ac2929f47c7b4de87e8 100644 (file)
@@ -128,8 +128,9 @@ private:
         throw std::runtime_error(boost::str(boost::format("unable to match content with `%s`") % cd.opts.at("stringmatch")));
       }
 
+      int weight = 0;
       try {
-        stoi(content);
+        weight = stoi(content);
         if(!status) {
           g_log<<Logger::Info<<"LUA record monitoring declaring "<<remstring<<" UP for URL "<<cd.url<<"!"<<" with WEIGHT "<<content<<"!"<<endl;
         }
@@ -140,7 +141,7 @@ private:
         }
       }
 
-      setWeight(cd, content);
+      setWeight(cd, weight);
       setUp(cd);
     }
     catch(std::exception& ne) {
@@ -232,15 +233,10 @@ private:
     }
   }
   
-  void setWeight(const CheckDesc& cd, string content){
+  void setWeight(const CheckDesc& cd, int weight){
     auto statuses = d_statuses.write_lock();
     auto& state = (*statuses)[cd];
-    try {
-      state->weight = stoi(content);
-    } catch (const PDNSException& e) {
-      // set weight to 0
-      state->weight = 0;
-    }
+    state->weight = weight;
     if (state->first) {
       state->first = false;
     }