From 0e6fb6c84f8e48dd693b980d113cea9ae661fcdc Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Sun, 18 Feb 2024 13:11:53 +0100 Subject: [PATCH] ADD: added a redmine api exception --- include/Redmine/Exception/Api.hpp | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 include/Redmine/Exception/Api.hpp diff --git a/include/Redmine/Exception/Api.hpp b/include/Redmine/Exception/Api.hpp new file mode 100644 index 0000000..3809a03 --- /dev/null +++ b/include/Redmine/Exception/Api.hpp @@ -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 . +*/ + +/** + * @brief The main namespace of this library for Redmine related datatypes, classes, and functions + * + */ +#include +#include +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 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 &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::vector 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 \ No newline at end of file