mirror of
https://github.com/Telecominfraproject/ols-ucentral-client.git
synced 2026-01-27 10:21:46 +00:00
Add discrete exception type for gNMI errors
This commit is contained in:
committed by
Kostiantyn Buravchenko
parent
1b869b9d9d
commit
dffe061778
@@ -197,7 +197,7 @@ std::string gnmi_get(const std::string &yang_path)
|
||||
|
||||
if (!status.ok())
|
||||
{
|
||||
throw std::runtime_error{
|
||||
throw gnmi_exception{
|
||||
"gNMI get operation wasn't successful: "
|
||||
+ status.error_message() + "; error code "
|
||||
+ std::to_string(status.error_code())};
|
||||
@@ -205,25 +205,25 @@ std::string gnmi_get(const std::string &yang_path)
|
||||
|
||||
if (gres.notification_size() != 1)
|
||||
{
|
||||
throw std::runtime_error{"Unsupported notification size"};
|
||||
throw gnmi_exception{"Unsupported notification size"};
|
||||
}
|
||||
|
||||
gnmi::Notification notification = gres.notification(0);
|
||||
if (notification.update_size() != 1)
|
||||
{
|
||||
throw std::runtime_error{"Unsupported update size"};
|
||||
throw gnmi_exception{"Unsupported update size"};
|
||||
}
|
||||
|
||||
gnmi::Update update = notification.update(0);
|
||||
if (!update.has_val())
|
||||
{
|
||||
throw std::runtime_error{"Empty value"};
|
||||
throw gnmi_exception{"Empty value"};
|
||||
}
|
||||
|
||||
gnmi::TypedValue value = update.val();
|
||||
if (!value.has_json_ietf_val())
|
||||
{
|
||||
throw std::runtime_error{"Empty JSON value"};
|
||||
throw gnmi_exception{"Empty JSON value"};
|
||||
}
|
||||
|
||||
return value.json_ietf_val();
|
||||
@@ -259,10 +259,10 @@ void gnmi_operation::execute()
|
||||
|
||||
if (!status.ok())
|
||||
{
|
||||
throw std::runtime_error{
|
||||
throw gnmi_exception{
|
||||
"gNMI set operation wasn't successful: "
|
||||
+ status.error_message() + "; error code "
|
||||
+ std::to_string(status.error_code())};
|
||||
+ status.error_message() + "; error code "
|
||||
+ std::to_string(status.error_code())};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <gnmi.pb.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,6 +16,10 @@ split_string(std::string str, const std::string &delimiter);
|
||||
|
||||
void convert_yang_path_to_proto(std::string yang_path, gnmi::Path *proto_path);
|
||||
|
||||
class gnmi_exception : public std::runtime_error {
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get value by specified path.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user