redmine-api-cpp/src/Redmine/Object.cpp

46 lines
1.6 KiB
C++

/*
* Copyright (C) 2024 Dominik Meyer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Redmine/Object.hpp>
#define LOGURU_WITH_STREAMS 1
#include <loguru.hpp>
void Redmine::Object::_baseVerify(const nlohmann::json &data, const std::string &objectName)
{
if (data.empty())
{
DLOG_S(ERROR) << "provided data is empty";
throw std::invalid_argument("provided data is empty");
}
if (!data.is_object())
{
DLOG_S(ERROR) << "provided data is not a json object/hash";
throw std::invalid_argument("provided data is not a json objects/hash");
}
if (!data.contains(objectName))
{
DLOG_S(ERROR) << "provided data does not contain object information (" << objectName << ")";
throw std::invalid_argument("provided data does not contain object information (" + objectName + ")");
}
if (data[objectName].empty())
{
DLOG_S(ERROR) << "provided object information is empty";
throw std::invalid_argument("provided object information is empty");
}
}