refactor(eventsub): enforce static error categories (#5903)
This commit is contained in:
@@ -3,8 +3,7 @@ boost::json::result_for<{{enum.full_name}}, boost::json::value>::type tag_invoke
|
||||
{
|
||||
if (!jvRoot.is_string())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeString{"{{enum.full_name}} must be a string"};
|
||||
return boost::system::error_code{129, errorMustBeString};
|
||||
EVENTSUB_BAIL_HERE(error::Kind::ExpectedString);
|
||||
}
|
||||
std::string_view eString(jvRoot.get_string());
|
||||
|
||||
@@ -16,6 +15,5 @@ boost::json::result_for<{{enum.full_name}}, boost::json::value>::type tag_invoke
|
||||
}
|
||||
{%- endfor %}
|
||||
|
||||
static const error::ApplicationErrorCategory errorEnumNameDidNotExist{"{{enum.full_name}} did not have a constant that matched this string"};
|
||||
return boost::system::error_code{129, errorEnumNameDidNotExist};
|
||||
EVENTSUB_BAIL_HERE(error::Kind::UnknownEnumValue);
|
||||
}
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
static const error::ApplicationErrorCategory error_missing_field_{{field.name}}{"Missing required key {{field.json_name}}"};
|
||||
return boost::system::error_code{129, error_missing_field_{{field.name}}};
|
||||
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
|
||||
|
||||
@@ -4,28 +4,24 @@ boost::json::result_for<{{struct.full_name}}, boost::json::value>::type tag_invo
|
||||
{% if struct.inner_root %}
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{"{{struct.full_name}} must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
|
||||
}
|
||||
const auto &outerRoot = jvRoot.get_object();
|
||||
|
||||
const auto *jvInnerRoot = outerRoot.if_contains("{{struct.inner_root}}");
|
||||
if (jvInnerRoot == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMissing{"{{struct.full_name}}'s key {{struct.inner_root}} is missing"};
|
||||
return boost::system::error_code{129, errorMissing};
|
||||
EVENTSUB_BAIL_HERE(error::Kind::InnerRootMissing);
|
||||
}
|
||||
if (!jvInnerRoot->is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{"{{struct.full_name}}'s {{struct.inner_root}} must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
|
||||
}
|
||||
const auto &root = jvInnerRoot->get_object();
|
||||
{% else %}
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{"{{struct.full_name}} must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user