refactor(eventsub): enforce static error categories (#5903)

This commit is contained in:
nerix
2025-02-07 16:37:53 +01:00
committed by GitHub
parent 9260e72a0b
commit f37676fe1c
20 changed files with 374 additions and 1049 deletions
@@ -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 %}