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
@@ -1,6 +1,6 @@
// WARNING: This file is automatically generated. Any changes will be lost.
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
#include "twitch-eventsub-ws/errors.hpp"
#include "twitch-eventsub-ws/detail/errors.hpp"
#include "twitch-eventsub-ws/payloads/session-welcome.hpp"
#include <boost/json.hpp>
@@ -12,33 +12,25 @@ boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
{
if (!jvRoot.is_object())
{
static const error::ApplicationErrorCategory errorMustBeObject{
"Payload 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("session");
if (jvInnerRoot == nullptr)
{
static const error::ApplicationErrorCategory errorMissing{
"Payload's key session is missing"};
return boost::system::error_code{129, errorMissing};
EVENTSUB_BAIL_HERE(error::Kind::InnerRootMissing);
}
if (!jvInnerRoot->is_object())
{
static const error::ApplicationErrorCategory errorMustBeObject{
"Payload's session must be an object"};
return boost::system::error_code{129, errorMustBeObject};
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
}
const auto &root = jvInnerRoot->get_object();
const auto *jvid = root.if_contains("id");
if (jvid == nullptr)
{
static const error::ApplicationErrorCategory error_missing_field_id{
"Missing required key id"};
return boost::system::error_code{129, error_missing_field_id};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto id = boost::json::try_value_to<std::string>(*jvid);