Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:33

0001 #pragma once
0002 
0003 #include <nlohmann/json.hpp>
0004 
0005 namespace nopayloadclient {
0006 
0007 class BaseException : public std::exception {
0008     private:
0009         int code_ = 1;
0010         std::string pretext_ = "BaseException: ";
0011         std::string message_;
0012     public:
0013   using std::exception::what;
0014         BaseException(std::string msg) : message_(msg) {}
0015         BaseException(int code, std::string pretext, std::string msg) {
0016             code_ = code;
0017             pretext_ = pretext;
0018             message_ = msg;
0019         }
0020         std::string what () {
0021             return message_;
0022         }
0023         nlohmann::json jsonify() {
0024             std::string msg = pretext_ + message_;
0025             return nlohmann::json::object({{"code", code_}, {"msg", msg}});
0026         }
0027 };
0028 
0029 
0030 class PayloadException : public BaseException {
0031     public:
0032         PayloadException(std::string msg) :
0033          BaseException(2, "PayloadException: ", msg) {}
0034 };
0035 
0036 
0037 class DataBaseException : public BaseException {
0038     private:
0039 //        int http_code_;
0040     public:
0041         DataBaseException(std::string msg) :
0042             BaseException(3, "DataBaseException: ", msg) {}
0043 };
0044 
0045 
0046 class IOVException : public BaseException {
0047     public:
0048         IOVException(std::string msg) :
0049          BaseException(4, "IOVException: ", msg) {}
0050 };
0051 
0052 /*
0053 class HttpException : public BaseException {
0054     private:
0055         int http_code_;
0056     public:
0057         HttpException(std::string msg, int http_code) :
0058             BaseException(3, "DataBaseException: ", msg) {
0059                 http_code_ = http_code;
0060         }
0061         nlohmann::json jsonify() {
0062             std::string msg = pretext_ + message_ + "(http code: " + http_code_ + ")";
0063             return nlohmann::json::object({{"code", code_}, {"msg", msg}});
0064         }
0065 };
0066 */
0067 }