forked from Vytax/hippo
/
error.cpp
171 lines (150 loc) · 4.56 KB
/
error.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "error.h"
#include "Logger.h"
Error::Error(QObject *parent) :
QObject(parent)
{
}
void Error::readExceptions(hash data) {
if (data.contains(1))
readUserException(data[1].value<hash>());
if (data.contains(2))
readSystemException(data[2].value<hash>());
if (data.contains(3))
readNotFoundException(data[3].value<hash>());
}
void Error::readUserException(hash data) {
if (!data.contains(1)) {
LOG_ERROR("Empty User Exception");
return;
}
bool ok;
int errorCode = data[1].toInt(&ok);
if (!ok) {
LOG_ERROR("Unknown User Exception");
return;
}
EDAMErrorCode(errorCode);
QString parameter;
if (data.contains(2)) {
parameter = QString::fromUtf8(data[2].toByteArray());
LOG_INFO(parameter);
}
}
void Error::readSystemException(hash data) {
if (!data.contains(1)) {
LOG_ERROR("Empty User Exception");
return;
}
bool ok;
int errorCode = data[1].toInt(&ok);
if (!ok) {
LOG_ERROR("Unknown User Exception");
return;
}
EDAMErrorCode(errorCode);
if (data.contains(2)) {
QString message = data[2].toString();
LOG_INFO(message);
}
if (data.contains(3)) {
int rateLimitDuration = data[3].toInt();
LOG_INFO(QString("Rate Limit Duration: %1 s.").arg(rateLimitDuration));
}
}
void Error::readNotFoundException(hash data) {
QString e("Not Found Exception");
if (data.contains(1)) {
QString identifier = data[1].toString();
e.append(" Identifier:");
e.append(identifier);
}
if (data.contains(2)) {
QString key = data[2].toString();
e.append(" Key:");
e.append(key);
}
LOG_ERROR(e);
}
void Error::EDAMErrorCode(int errorCode) {
switch (errorCode) {
case 1:
LOG_ERROR("UNKNOWN");
LOG_INFO("No information available about the error");
return;
case 2:
LOG_ERROR("BAD_DATA_FORMAT");
LOG_INFO("The format of the request data was incorrect");
return;
case 3:
LOG_ERROR("PERMISSION_DENIED");
LOG_INFO("Not permitted to perform action");
return;
case 4:
LOG_ERROR("INTERNAL_ERROR");
LOG_INFO("Unexpected problem with the service");
return;
case 5:
LOG_ERROR("DATA_REQUIRED");
LOG_INFO("A required parameter/field was absent");
return;
case 6:
LOG_ERROR("LIMIT_REACHED");
LOG_INFO("Operation denied due to data model limit");
return;
case 7:
LOG_ERROR("QUOTA_REACHED");
LOG_INFO("Operation denied due to user storage limit");
return;
case 8:
LOG_ERROR("INVALID_AUTH");
LOG_INFO("Username and/or password incorrect");
return;
case 9:
LOG_ERROR("AUTH_EXPIRED");
LOG_INFO("Authentication token expired");
return;
case 10:
LOG_ERROR("DATA_CONFLICT");
LOG_INFO("Change denied due to data model conflict");
return;
case 11:
LOG_ERROR("ENML_VALIDATION");
LOG_INFO("Content of submitted note was malformed");
return;
case 12:
LOG_ERROR("SHARD_UNAVAILABLE");
LOG_INFO("Service shard with account data is temporarily down");
return;
case 13:
LOG_ERROR("LEN_TOO_SHORT");
LOG_INFO("Operation denied due to data model limit, where something such as a string length was too short");
return;
case 14:
LOG_ERROR("LEN_TOO_LONG");
LOG_INFO("Operation denied due to data model limit, where something such as a string length was too long");
return;
case 15:
LOG_ERROR("TOO_FEW");
LOG_INFO("Operation denied due to data model limit, where there were too few of something.");
return;
case 16:
LOG_ERROR("TOO_MANY");
LOG_INFO("Operation denied due to data model limit, where there were too many of something.");
return;
case 17:
LOG_ERROR("UNSUPPORTED_OPERATION");
LOG_INFO("Operation denied because it is currently unsupported.");
return;
case 18:
LOG_ERROR("TAKEN_DOWN");
LOG_INFO("Operation denied because access to the corresponding object is prohibited in response to a take-down notice.");
return;
case 19:
LOG_ERROR("RATE_LIMIT_REACHED");
LOG_INFO("Operation denied because the calling application has reached its hourly API call limit for this user.");
return;
default:
LOG_ERROR("Unknown User Exception.");
return;
}
}