@zennify/sdk-js 1.3.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/types/RequestError.d.ts +2 -2
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/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 {};
|