1414// /
1515
1616#include " Monitoring/MonitoringFactory.h"
17+ #include " Exceptions/MonitoringException.h"
1718#include < functional>
18- #include < stdexcept>
1919#include < boost/algorithm/string.hpp>
2020#include " MonLogger.h"
2121#include " UriParser/UriParser.h"
@@ -87,7 +87,7 @@ std::unique_ptr<Backend> getInfluxDbv2(http::url uri)
8787 transport->addHeader (" Authorization: Token " + token);
8888 return std::make_unique<backends::InfluxDB>(std::move (transport));
8989#else
90- throw std::runtime_error ( " HTTP transport is not enabled" );
90+ throw MonitoringException ( " Factory " , " HTTP transport is not enabled" );
9191#endif
9292}
9393
@@ -120,10 +120,10 @@ std::unique_ptr<Backend> getInfluxDb(http::url uri)
120120 auto transport = std::make_unique<transports::Kafka>(uri.host , uri.port , uri.search );
121121 return std::make_unique<backends::InfluxDB>(std::move (transport));
122122#else
123- throw std::runtime_error ( " Kafka transport is not enabled" );
123+ throw MonitoringException ( " Factory " , " Kafka transport is not enabled" );
124124#endif
125125 }
126- throw std::runtime_error ( " InfluxDB transport not supported: " + uri.protocol );
126+ throw MonitoringException ( " Factory " , " InfluxDB transport not supported: " + uri.protocol );
127127}
128128
129129#ifdef O2_MONITORING_WITH_APPMON
@@ -134,7 +134,7 @@ std::unique_ptr<Backend> getApMon(http::url uri)
134134#else
135135std::unique_ptr<Backend> getApMon (http::url /* uri*/ )
136136{
137- throw std::runtime_error ( " ApMon backend is not enabled" );
137+ throw MonitoringException ( " Factory " , " ApMon backend is not enabled" );
138138}
139139#endif
140140
@@ -171,19 +171,22 @@ std::unique_ptr<Backend> MonitoringFactory::GetBackend(std::string& url)
171171
172172 http::url parsedUrl = http::ParseHttpUrl (url);
173173 if (parsedUrl.protocol .empty ()) {
174- throw std::runtime_error ( " Ill-formed URI" );
174+ throw MonitoringException ( " Factory " , " Ill-formed URI" );
175175 }
176176
177177 auto iterator = map.find (parsedUrl.protocol );
178178 if (iterator == map.end ()) {
179- throw std::runtime_error ( " Unrecognized backend " + parsedUrl.protocol );
179+ throw MonitoringException ( " Factory " , " Unrecognized backend " + parsedUrl.protocol );
180180 }
181-
182- auto backend = iterator->second (parsedUrl);
183- if (!parsedUrl.path .empty () && parsedUrl.path != " /" ) {
184- SetVerbosity (parsedUrl.path .substr (parsedUrl.path .rfind (" /" )), backend);
181+ try {
182+ auto backend = iterator->second (parsedUrl);
183+ if (!parsedUrl.path .empty () && parsedUrl.path != " /" ) {
184+ SetVerbosity (parsedUrl.path .substr (parsedUrl.path .rfind (" /" )), backend);
185+ }
186+ return backend;
187+ } catch (...) {
188+ throw MonitoringException (" Factory" , " Unable to create backend " + parsedUrl.url );
185189 }
186- return backend;
187190}
188191
189192std::unique_ptr<Monitoring> MonitoringFactory::Get (std::string urlsString)
0 commit comments