@zennify/sdk-js 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RequestError.js +5 -4
- package/package.json +1 -1
- package/src/RequestError.ts +5 -4
- package/src/errors.ts +3 -0
- package/translations/en_US.json +12 -0
- package/translations/pt_BR.json +12 -0
- package/types/RequestError.d.ts +2 -2
- package/types/errors.d.ts +3 -0
package/dist/RequestError.js
CHANGED
|
@@ -13,13 +13,14 @@ const replacer = (body, value) => {
|
|
|
13
13
|
return body[value.slice(1, -1)];
|
|
14
14
|
};
|
|
15
15
|
class ZennifyAPIRequestError extends Error {
|
|
16
|
-
|
|
17
|
-
code = 0;
|
|
16
|
+
code = "UNKNOWN_ERROR";
|
|
18
17
|
body;
|
|
18
|
+
status = 0;
|
|
19
19
|
constructor(response, body) {
|
|
20
20
|
super();
|
|
21
21
|
this.body = body;
|
|
22
22
|
this.status = response.status;
|
|
23
|
+
this.code = body.code || 'UNKNOWN_ERROR';
|
|
23
24
|
if (this.status === 401) {
|
|
24
25
|
this.name = "Usuário inválido";
|
|
25
26
|
this.message = "Por favor, se re-autentique";
|
|
@@ -35,8 +36,8 @@ class ZennifyAPIRequestError extends Error {
|
|
|
35
36
|
this.message = "Suas ações estão sendo limitadas!";
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
|
-
else if (
|
|
39
|
-
const error = errors_translations[var_1.ZENNIFY_API_RESPONSE_LANGUAGE][
|
|
39
|
+
else if (this.code) {
|
|
40
|
+
const error = errors_translations[var_1.ZENNIFY_API_RESPONSE_LANGUAGE][this.code] ||
|
|
40
41
|
errors_translations[var_1.ZENNIFY_API_RESPONSE_LANGUAGE]["UNKNOWN_TRANSLATION"];
|
|
41
42
|
this.name = error.name
|
|
42
43
|
.replace(match_regex, (value) => replacer(body, value));
|
package/package.json
CHANGED
package/src/RequestError.ts
CHANGED
|
@@ -15,9 +15,9 @@ type Body = Record<string, any> & {
|
|
|
15
15
|
|
|
16
16
|
export class ZennifyAPIRequestError extends Error {
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
code: number = 0;
|
|
18
|
+
code: keyof APIErrors = "UNKNOWN_ERROR";
|
|
20
19
|
body: Body
|
|
20
|
+
status: number = 0;
|
|
21
21
|
|
|
22
22
|
constructor(response: Response, body: Body) {
|
|
23
23
|
|
|
@@ -25,6 +25,7 @@ export class ZennifyAPIRequestError extends Error {
|
|
|
25
25
|
|
|
26
26
|
this.body = body;
|
|
27
27
|
this.status = response.status;
|
|
28
|
+
this.code = body.code || 'UNKNOWN_ERROR'
|
|
28
29
|
|
|
29
30
|
if (this.status === 401) {
|
|
30
31
|
this.name = "Usuário inválido";
|
|
@@ -41,10 +42,10 @@ export class ZennifyAPIRequestError extends Error {
|
|
|
41
42
|
this.message = "Suas ações estão sendo limitadas!";
|
|
42
43
|
return;
|
|
43
44
|
}
|
|
44
|
-
else if (
|
|
45
|
+
else if (this.code) {
|
|
45
46
|
|
|
46
47
|
const error: { name: string, message: string } =
|
|
47
|
-
errors_translations[ZENNIFY_API_RESPONSE_LANGUAGE][
|
|
48
|
+
errors_translations[ZENNIFY_API_RESPONSE_LANGUAGE][this.code] ||
|
|
48
49
|
errors_translations[ZENNIFY_API_RESPONSE_LANGUAGE]["UNKNOWN_TRANSLATION"];
|
|
49
50
|
|
|
50
51
|
this.name = error.name
|
package/src/errors.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface APIErrors {
|
|
|
17
17
|
'EXPECTED_A_STRING': ExpectedAdditionalData;
|
|
18
18
|
'EXPECTED_A_NUMBER': ExpectedAdditionalData;
|
|
19
19
|
'EXPECTED_A_VALID_ID': ExpectedAdditionalData;
|
|
20
|
+
'EXPECTED_A_VALID_SNOWFLAKE_ID': {};
|
|
20
21
|
'DUPLICATED_VALUES_ISNT_ALLOWED': {};
|
|
21
22
|
// = oAuth errors
|
|
22
23
|
'GRANT_CODE_MISSING_IN_QUERY': {};
|
|
@@ -111,6 +112,8 @@ export interface APIErrors {
|
|
|
111
112
|
'DISABLE_REQUIRE_CODE_GRANT': {};
|
|
112
113
|
'UNKNOWN_DISCORD_CHANNEL': {};
|
|
113
114
|
'ANOTHER_STORE_HAS_THIS_BOT': {}
|
|
115
|
+
'UNKNOWN_APPLICATION': {}
|
|
116
|
+
'WAIT_APPLICATION_UPLOAD': {}
|
|
114
117
|
// product errors
|
|
115
118
|
'UNKNOWN_PRODUCT': {};
|
|
116
119
|
'INVALID_PRODUCT_NAME': {};
|
package/translations/en_US.json
CHANGED
|
@@ -47,6 +47,10 @@
|
|
|
47
47
|
"name": "Expected a valid ID",
|
|
48
48
|
"message": "IDs must be integers between 0 and 2.147.483.647"
|
|
49
49
|
},
|
|
50
|
+
"EXPECTED_A_VALID_SNOWFLAKE_ID": {
|
|
51
|
+
"name": "A valid ID was expected",
|
|
52
|
+
"message": "Please check if the ID is valid."
|
|
53
|
+
},
|
|
50
54
|
"STORE_ALREADY_CONFIGURED": {
|
|
51
55
|
"name": "This store is already configured",
|
|
52
56
|
"message": "Go back to dashboard and access the store again"
|
|
@@ -283,6 +287,14 @@
|
|
|
283
287
|
"name": "Another store has already configured this bot!",
|
|
284
288
|
"message": "Please configure a different bot."
|
|
285
289
|
},
|
|
290
|
+
"UNKNOWN_APPLICATION": {
|
|
291
|
+
"name": "Application not found",
|
|
292
|
+
"message": "Please contact support."
|
|
293
|
+
},
|
|
294
|
+
"WAIT_APPLICATION_UPLOAD": {
|
|
295
|
+
"name": "Please wait for your application to be uploaded!",
|
|
296
|
+
"message": "It should be uploaded in a few minutes."
|
|
297
|
+
},
|
|
286
298
|
"UNKNOWN_DISCORD_CHANNEL": {
|
|
287
299
|
"name": "Unknown Discord channel",
|
|
288
300
|
"message": "Perhaps this channel no longer exists."
|
package/translations/pt_BR.json
CHANGED
|
@@ -47,6 +47,10 @@
|
|
|
47
47
|
"name": "Era esperado um ID válido",
|
|
48
48
|
"message": "Recebido \"{received}\" com o tipo {type}, Verifique o campo \"{field}\". IDs devem ser inteiros entre 0 e 2.147.483.647"
|
|
49
49
|
},
|
|
50
|
+
"EXPECTED_A_VALID_SNOWFLAKE_ID": {
|
|
51
|
+
"name": "Era esperado um ID válido",
|
|
52
|
+
"message": "Verifique se o ID é válido"
|
|
53
|
+
},
|
|
50
54
|
"DUPLICATED_VALUES_ISNT_ALLOWED": {
|
|
51
55
|
"name": "Valores duplicados não são permitidos",
|
|
52
56
|
"message": "Recebido \"{received}\" com o tipo {type}, Verifique o campo \"{field}\""
|
|
@@ -283,6 +287,14 @@
|
|
|
283
287
|
"name": "Outra loja já configurou este bot!",
|
|
284
288
|
"message": "Configure um bot diferente"
|
|
285
289
|
},
|
|
290
|
+
"UNKNOWN_APPLICATION": {
|
|
291
|
+
"name": "Aplicação não encontrada",
|
|
292
|
+
"message": "Entre em contato com o suporte."
|
|
293
|
+
},
|
|
294
|
+
"WAIT_APPLICATION_UPLOAD": {
|
|
295
|
+
"name": "Aguarde o envio da sua aplicação!",
|
|
296
|
+
"message": "Ela deve ser enviada em alguns minutos"
|
|
297
|
+
},
|
|
286
298
|
"UNKNOWN_DISCORD_CHANNEL": {
|
|
287
299
|
"name": "Canal do Discord desconhecido",
|
|
288
300
|
"message": "Talvez esse canal não exista mais."
|
package/types/RequestError.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ type Body = Record<string, any> & {
|
|
|
3
3
|
code: keyof APIErrors;
|
|
4
4
|
};
|
|
5
5
|
export declare class ZennifyAPIRequestError extends Error {
|
|
6
|
-
|
|
7
|
-
code: number;
|
|
6
|
+
code: keyof APIErrors;
|
|
8
7
|
body: Body;
|
|
8
|
+
status: number;
|
|
9
9
|
constructor(response: Response, body: Body);
|
|
10
10
|
}
|
|
11
11
|
export {};
|
package/types/errors.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface APIErrors {
|
|
|
16
16
|
'EXPECTED_A_STRING': ExpectedAdditionalData;
|
|
17
17
|
'EXPECTED_A_NUMBER': ExpectedAdditionalData;
|
|
18
18
|
'EXPECTED_A_VALID_ID': ExpectedAdditionalData;
|
|
19
|
+
'EXPECTED_A_VALID_SNOWFLAKE_ID': {};
|
|
19
20
|
'DUPLICATED_VALUES_ISNT_ALLOWED': {};
|
|
20
21
|
'GRANT_CODE_MISSING_IN_QUERY': {};
|
|
21
22
|
'INVALID_SCOPE': {};
|
|
@@ -97,6 +98,8 @@ export interface APIErrors {
|
|
|
97
98
|
'DISABLE_REQUIRE_CODE_GRANT': {};
|
|
98
99
|
'UNKNOWN_DISCORD_CHANNEL': {};
|
|
99
100
|
'ANOTHER_STORE_HAS_THIS_BOT': {};
|
|
101
|
+
'UNKNOWN_APPLICATION': {};
|
|
102
|
+
'WAIT_APPLICATION_UPLOAD': {};
|
|
100
103
|
'UNKNOWN_PRODUCT': {};
|
|
101
104
|
'INVALID_PRODUCT_NAME': {};
|
|
102
105
|
'INVALID_PRODUCT_VALUE': {};
|