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/stream-offline-v1.hpp"
#include <boost/json.hpp>
@@ -12,20 +12,14 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
{
if (!jvRoot.is_object())
{
static const error::ApplicationErrorCategory errorMustBeObject{
"Event must be an object"};
return boost::system::error_code{129, errorMustBeObject};
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
}
const auto &root = jvRoot.get_object();
const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id");
if (jvbroadcasterUserID == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_broadcasterUserID{
"Missing required key broadcaster_user_id"};
return boost::system::error_code{129,
error_missing_field_broadcasterUserID};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserID =
@@ -40,11 +34,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
root.if_contains("broadcaster_user_login");
if (jvbroadcasterUserLogin == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_broadcasterUserLogin{
"Missing required key broadcaster_user_login"};
return boost::system::error_code{
129, error_missing_field_broadcasterUserLogin};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserLogin =
@@ -59,11 +49,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
root.if_contains("broadcaster_user_name");
if (jvbroadcasterUserName == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_broadcasterUserName{
"Missing required key broadcaster_user_name"};
return boost::system::error_code{
129, error_missing_field_broadcasterUserName};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserName =
@@ -86,19 +72,14 @@ 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 &root = jvRoot.get_object();
const auto *jvsubscription = root.if_contains("subscription");
if (jvsubscription == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_subscription{
"Missing required key subscription"};
return boost::system::error_code{129, error_missing_field_subscription};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto subscription =
@@ -112,9 +93,7 @@ boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
const auto *jvevent = root.if_contains("event");
if (jvevent == nullptr)
{
static const error::ApplicationErrorCategory error_missing_field_event{
"Missing required key event"};
return boost::system::error_code{129, error_missing_field_event};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto event = boost::json::try_value_to<Event>(*jvevent);