ADD: added a redmine api exception
This commit is contained in:
parent
417a598cb5
commit
0e6fb6c84f
94
include/Redmine/Exception/Api.hpp
Normal file
94
include/Redmine/Exception/Api.hpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#pragma once
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The main namespace of this library for Redmine related datatypes, classes, and functions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <vector>
|
||||||
|
namespace Redmine
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief namespace for all exceptions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
namespace Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief exception returning all errors generated by an redmine api request
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Api : public std::exception
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
/// the overall exception msg
|
||||||
|
std::string msg_;
|
||||||
|
|
||||||
|
/// vector for storing all api errors of a request
|
||||||
|
std::vector<std::string> errors_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief constructor for just creating an exception
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
explicit Api(const char* message) : msg_(message) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor for creating an exception and add error messages
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* @param errors
|
||||||
|
*/
|
||||||
|
Api(const char* message, const std::vector<std::string> &errors) :
|
||||||
|
msg_(message), errors_(errors) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief add error to an existing exception
|
||||||
|
*
|
||||||
|
* @param error
|
||||||
|
*/
|
||||||
|
void addError(const std::string &error) {errors_.push_back(error);}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return all errors of an exception
|
||||||
|
*
|
||||||
|
* @return std::vector<std::string>
|
||||||
|
*/
|
||||||
|
std::vector<std::string> getErrors() const {return errors_;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief return the what of an exception
|
||||||
|
*
|
||||||
|
* @return const char*
|
||||||
|
*/
|
||||||
|
virtual const char* what() const noexcept {
|
||||||
|
return msg_.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Api() noexcept {}
|
||||||
|
}; // class Api
|
||||||
|
|
||||||
|
}; // namespace Exception
|
||||||
|
|
||||||
|
}; // namespace Redmine
|
Loading…
Reference in New Issue
Block a user