iberbox  2.1.2
error.h
Go to the documentation of this file.
1 
10 #ifndef ERROR_H
11 #define ERROR_H
12 
13 #include "iberbox/config.h"
14 #ifdef USE_SCAPIX
15 #include <scapix/bridge/object.h>
16 #endif
17 
18 #include <string>
19 
20 namespace iberbox {
21 
25 class Error
26 #ifdef USE_SCAPIX
27  : public scapix::bridge::object<Error>
28 #endif
29 {
30 public:
35  enum ErrorType
36  {
37  E_SUCCESS = 0,
40  E_SESSION = 3,
41  E_CRYPTO = 4,
43  E_EXPIRED = 6,
45  E_BUSY = 8,
46  E_UNKNOWN = 9,
47  E_FAST = 10,
49  E_MANY = 12,
50  E_QUOTA = 13,
51  E_TAKEDOWN = 14,
52  E_RANGE = 15,
54  E_LOOP = 17,
55  E_IO = 18,
57  E_COUPON = 20,
60  };
61 
68  static const char *getTypeName(int type)
69  {
70  static const char *sErrorNames[] =
71  {
72  "Success",
73  "Not found",
74  "Forbidden",
75  "Session not valid",
76  "Cryptographic error",
77  "Wrong parameters",
78  "Expired",
79  "Already exists",
80  "Server is busy",
81  "Unknown error",
82  "Too fast requests",
83  "Temporarily unavailable",
84  "Too many attempts",
85  "Quota exceeded",
86  "Taken down",
87  "Range not satisfiable",
88  "Cancelled",
89  "Loop detected",
90  "I/O error",
91  "There is a problem with your invoicing information",
92  "Invalid coupon",
93  "Incomplete"
94  };
95  static_assert((sizeof(sErrorNames) / sizeof(sErrorNames[0]) == Error::LAST), "Invalid number of error names");
96  return type < Error::LAST ? sErrorNames[type] : "INVALID";
97  }
98 
105  static const std::string getTypeNameString(unsigned type)
106  {
107  return getTypeName(type);
108  }
109 
110  Error(int type = E_SUCCESS) { mType = type; }
111  virtual ~Error() { }
117  int getType() const { return mType; }
123  const char *getName() const { return getTypeName(mType); }
129  const std::string getNameString() const { return getTypeNameString(mType); }
130 
131 #ifndef EMSCRIPTEN
132 protected:
133 #endif
134 
135  int mType;
136 };
137 
138 }
139 
140 #endif // ERROR_H
141 
Definition: error.h:54
Definition: error.h:58
Definition: error.h:48
Definition: error.h:47
Definition: error.h:38
Definition: error.h:46
Definition: error.h:49
The iberbox namespace.
Definition: task.h:21
Definition: error.h:57
Definition: error.h:59
Definition: error.h:50
int getType() const
Gets the type of the error.
Definition: error.h:117
static const std::string getTypeNameString(unsigned type)
Gets the event type name.
Definition: error.h:105
Definition: error.h:51
Error(int type=E_SUCCESS)
Definition: error.h:110
const std::string getNameString() const
Gets the Name String object.
Definition: error.h:129
ErrorType
The error type.
Definition: error.h:35
Definition: error.h:42
Definition: error.h:44
virtual ~Error()
Definition: error.h:111
Definition: error.h:41
The error class.
Definition: error.h:25
Definition: error.h:56
Definition: error.h:43
Definition: error.h:53
Definition: error.h:55
Definition: error.h:45
Definition: error.h:37
Definition: error.h:40
const char * getName() const
Gets the Name object.
Definition: error.h:123
static const char * getTypeName(int type)
Gets the event type name.
Definition: error.h:68
Definition: error.h:39
Definition: error.h:52