ismx-nexo-node-app 0.3.56 → 0.3.58
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/js/business/BusinessErrors.js +4 -1
- package/dist/js/repository/RepositoryRest.js +4 -0
- package/dist/js/repository/RepositoryRestFormal.js +1 -1
- package/dist/types/repository/RepositoryRest.d.ts +1 -0
- package/package.json +1 -1
- package/src/main/node/business/BusinessErrors.ts +5 -2
- package/src/main/node/repository/RepositoryRest.ts +4 -0
- package/src/main/node/repository/RepositoryRestFormal.ts +1 -1
|
@@ -75,7 +75,10 @@ class BusinessErrors {
|
|
|
75
75
|
}
|
|
76
76
|
isType(key, value, type, assertion) {
|
|
77
77
|
try {
|
|
78
|
-
|
|
78
|
+
let val = assertion(value);
|
|
79
|
+
if (type === 'number' && (Number.isNaN(val) || !Number.isFinite(val)))
|
|
80
|
+
throw new Error();
|
|
81
|
+
if (type === 'date' && (!(val instanceof Date) || isNaN(val.getTime())))
|
|
79
82
|
throw new Error();
|
|
80
83
|
}
|
|
81
84
|
catch (_a) {
|
|
@@ -48,6 +48,10 @@ class RepositoryRest extends Repository_1.default {
|
|
|
48
48
|
};
|
|
49
49
|
(_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.onResponse) === null || _b === void 0 ? void 0 : _b.call(_a, response);
|
|
50
50
|
return response;
|
|
51
|
+
}).catch((error) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
(_b = (_a = this.options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
54
|
+
throw error;
|
|
51
55
|
});
|
|
52
56
|
});
|
|
53
57
|
}
|
|
@@ -35,7 +35,7 @@ class RepositoryRestFormal extends RepositoryRest_1.default {
|
|
|
35
35
|
return {};
|
|
36
36
|
}))
|
|
37
37
|
.catch((error) => {
|
|
38
|
-
throw { id: "-1", code: "-1", description: "ConnectionError", error };
|
|
38
|
+
throw { id: "-1", code: "-1", description: "ConnectionError", error: error.getMessage() };
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -3,6 +3,7 @@ import { HttpRequest, HttpResponse } from "../api/Service";
|
|
|
3
3
|
export interface RestOptions {
|
|
4
4
|
interceptor?: (endpoint: string, request: HttpRequest) => HttpRequest | undefined;
|
|
5
5
|
onResponse?: (response: HttpResponse) => void;
|
|
6
|
+
onError?: (error: Error) => void;
|
|
6
7
|
}
|
|
7
8
|
export default class RepositoryRest<Body = any, Res = any> extends Repository {
|
|
8
9
|
private readonly baseUrl;
|
package/package.json
CHANGED
|
@@ -71,8 +71,11 @@ export default class BusinessErrors {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
isType<T>(key: string, value: string, type:string, assertion: (value:string)=>T): T {
|
|
74
|
-
try {
|
|
75
|
-
|
|
74
|
+
try {
|
|
75
|
+
let val = assertion(value);
|
|
76
|
+
if (type === 'number' && (Number.isNaN(val) || !Number.isFinite(val))) throw new Error();
|
|
77
|
+
if (type === 'date' && (!(val instanceof Date) || isNaN(val.getTime()))) throw new Error()
|
|
78
|
+
} catch { this.except("0021", key, type) }
|
|
76
79
|
return assertion(value);
|
|
77
80
|
}
|
|
78
81
|
|
|
@@ -5,6 +5,7 @@ import QueryUtils from "./utils/QueryUtils";
|
|
|
5
5
|
export interface RestOptions {
|
|
6
6
|
interceptor?: (endpoint: string, request: HttpRequest) => HttpRequest | undefined
|
|
7
7
|
onResponse?: (response: HttpResponse) => void;
|
|
8
|
+
onError?: (error: Error) => void
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
@@ -57,6 +58,9 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
|
57
58
|
};
|
|
58
59
|
this.options?.onResponse?.(response);
|
|
59
60
|
return response;
|
|
61
|
+
}).catch((error) => {
|
|
62
|
+
this.options.onError?.(error);
|
|
63
|
+
throw error;
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
66
|
|
|
@@ -24,7 +24,7 @@ export default class RepositoryRestFormal<Body=any, S=any> extends RepositoryRes
|
|
|
24
24
|
} else return {} as E;
|
|
25
25
|
})
|
|
26
26
|
.catch((error) => {
|
|
27
|
-
throw { id: "-1", code: "-1", description: "ConnectionError", error } as FormalError
|
|
27
|
+
throw { id: "-1", code: "-1", description: "ConnectionError", error: error.getMessage() } as FormalError
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
}
|