ismx-nexo-node-app 0.3.64 → 0.3.66
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/api/ServiceRestFormal.js +5 -2
- package/dist/js/business/BusinessErrors.js +11 -4
- package/dist/js/business/BusinessServer.js +3 -0
- package/dist/js/repository/RepositoryRestFormal.js +6 -5
- package/dist/types/api/ServiceRestFormal.d.ts +1 -1
- package/dist/types/business/BusinessErrors.d.ts +11 -6
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/main/node/api/ServiceRestFormal.ts +4 -3
- package/src/main/node/business/BusinessErrors.ts +17 -10
- package/src/main/node/business/BusinessServer.ts +2 -0
- package/src/main/node/index.ts +1 -1
- package/src/main/node/repository/RepositoryRestFormal.ts +5 -6
|
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const Service_1 = __importStar(require("./Service"));
|
|
39
39
|
const ServiceRest_1 = __importDefault(require("./ServiceRest"));
|
|
40
|
+
const BusinessErrors_1 = require("../business/BusinessErrors");
|
|
40
41
|
class ServiceRestFormal extends ServiceRest_1.default {
|
|
41
42
|
constructor(method, endpoint = "/") {
|
|
42
43
|
super(method, endpoint);
|
|
@@ -49,8 +50,10 @@ class ServiceRestFormal extends ServiceRest_1.default {
|
|
|
49
50
|
return Object.assign({}, response, { content });
|
|
50
51
|
}
|
|
51
52
|
catch (error) {
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
if (error instanceof BusinessErrors_1.FormalError)
|
|
54
|
+
throw error;
|
|
55
|
+
else
|
|
56
|
+
throw new BusinessErrors_1.FormalError({ code: "-1", description: "Internal server error", debug: error.message });
|
|
54
57
|
}
|
|
55
58
|
});
|
|
56
59
|
}
|
|
@@ -9,6 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FormalError = void 0;
|
|
13
|
+
class FormalError extends Error {
|
|
14
|
+
constructor(type) {
|
|
15
|
+
super();
|
|
16
|
+
this.type = type;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.FormalError = FormalError;
|
|
12
20
|
class BusinessErrors {
|
|
13
21
|
constructor() {
|
|
14
22
|
this.errors = {};
|
|
@@ -22,13 +30,12 @@ class BusinessErrors {
|
|
|
22
30
|
get(code, ...params) {
|
|
23
31
|
var _a, _b;
|
|
24
32
|
let error = (_a = this.errors[code]) !== null && _a !== void 0 ? _a : this.getFallback();
|
|
25
|
-
let result = Object.assign({}, error);
|
|
26
33
|
for (const p in params)
|
|
27
|
-
|
|
28
|
-
return
|
|
34
|
+
error.description = (_b = error.description) === null || _b === void 0 ? void 0 : _b.replace(`\${${p}}`, params[p]);
|
|
35
|
+
return error;
|
|
29
36
|
}
|
|
30
37
|
except(code, ...params) {
|
|
31
|
-
let error = this.get(code, ...params);
|
|
38
|
+
let error = new FormalError(this.get(code, ...params));
|
|
32
39
|
//this.onExcept?.(error)
|
|
33
40
|
throw error;
|
|
34
41
|
}
|
|
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const Service_1 = require("../api/Service");
|
|
39
39
|
const Business_1 = __importDefault(require("./Business"));
|
|
40
|
+
const BusinessErrors_1 = require("../business/BusinessErrors");
|
|
40
41
|
class BusinessServer extends Business_1.default {
|
|
41
42
|
constructor() {
|
|
42
43
|
super();
|
|
@@ -128,6 +129,8 @@ class BusinessServer extends Business_1.default {
|
|
|
128
129
|
catch (e) { }
|
|
129
130
|
if (error instanceof Service_1.HttpResponse)
|
|
130
131
|
response = error;
|
|
132
|
+
if (error instanceof BusinessErrors_1.FormalError)
|
|
133
|
+
response = error.type;
|
|
131
134
|
else
|
|
132
135
|
response = Service_1.HttpResponse.ko((_g = error.httpCode) !== null && _g !== void 0 ? _g : 500, error.content);
|
|
133
136
|
}
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const RepositoryRest_1 = __importDefault(require("./RepositoryRest"));
|
|
16
|
+
const BusinessErrors_1 = require("../business/BusinessErrors");
|
|
16
17
|
class RepositoryRestFormal extends RepositoryRest_1.default {
|
|
17
18
|
constructor(baseUrl, options) {
|
|
18
19
|
super(baseUrl, options);
|
|
@@ -29,16 +30,16 @@ class RepositoryRestFormal extends RepositoryRest_1.default {
|
|
|
29
30
|
if (content.code === "0")
|
|
30
31
|
return content.data;
|
|
31
32
|
else
|
|
32
|
-
throw { code: content.code, description: content.description };
|
|
33
|
+
throw new BusinessErrors_1.FormalError({ code: content.code, description: content.description });
|
|
33
34
|
}
|
|
34
35
|
else
|
|
35
|
-
throw { code: "-1", description: "Not formal response" };
|
|
36
|
+
throw new BusinessErrors_1.FormalError({ code: "-1", description: "Not formal response" });
|
|
36
37
|
}))
|
|
37
38
|
.catch((error) => {
|
|
38
|
-
|
|
39
|
-
if (error.code !== undefined)
|
|
39
|
+
if (error instanceof BusinessErrors_1.FormalError)
|
|
40
40
|
throw error;
|
|
41
|
-
|
|
41
|
+
else
|
|
42
|
+
throw new BusinessErrors_1.FormalError({ code: "-1", description: "ConnectionError", debug: error.message });
|
|
42
43
|
});
|
|
43
44
|
});
|
|
44
45
|
}
|
|
@@ -4,7 +4,7 @@ export interface Wrapper<T> {
|
|
|
4
4
|
code: string;
|
|
5
5
|
description: string;
|
|
6
6
|
data?: T;
|
|
7
|
-
|
|
7
|
+
degug?: string;
|
|
8
8
|
}
|
|
9
9
|
export default class ServiceRestFormal<Req = any, Res = any> extends ServiceRest<Req, Wrapper<Res>> {
|
|
10
10
|
constructor(method: string, endpoint?: string);
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
id
|
|
1
|
+
export interface ErrorType {
|
|
2
|
+
id?: string;
|
|
3
3
|
code: string;
|
|
4
4
|
description: string;
|
|
5
5
|
httpCode?: number;
|
|
6
6
|
group?: string;
|
|
7
|
+
debug?: any;
|
|
8
|
+
}
|
|
9
|
+
export declare class FormalError extends Error {
|
|
10
|
+
type: ErrorType;
|
|
11
|
+
constructor(type: ErrorType);
|
|
7
12
|
}
|
|
8
13
|
export default class BusinessErrors {
|
|
9
14
|
private errors;
|
|
10
15
|
init(): Promise<void>;
|
|
11
16
|
setErrors(errors: {
|
|
12
|
-
[key: string]:
|
|
17
|
+
[key: string]: ErrorType;
|
|
13
18
|
}): void;
|
|
14
|
-
get(code: string, ...params: string[]):
|
|
15
|
-
except(code: string, ...params: string[]):
|
|
19
|
+
get(code: string, ...params: string[]): ErrorType;
|
|
20
|
+
except(code: string, ...params: string[]): never;
|
|
16
21
|
notFound(endpoint: string): void;
|
|
17
22
|
unauthorized(): void;
|
|
18
23
|
getQuery(key: string, query: {
|
|
@@ -36,5 +41,5 @@ export default class BusinessErrors {
|
|
|
36
41
|
exists<T>(type: string, key: string, value: string, object?: T): T;
|
|
37
42
|
isRegex(key: string, value: string, regex: string): string;
|
|
38
43
|
isDate(key: string, value: string, format: string): Date;
|
|
39
|
-
getFallback():
|
|
44
|
+
getFallback(): ErrorType;
|
|
40
45
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare class BusinessServer extends _BusinessServer {
|
|
|
37
37
|
import BaseBusinessThread from "./business/BusinessThread";
|
|
38
38
|
export declare abstract class BusinessThread extends BaseBusinessThread {
|
|
39
39
|
}
|
|
40
|
-
import BaseBusinessErrors, {
|
|
40
|
+
import BaseBusinessErrors, { ErrorType as BaseFormalError } from "./business/BusinessErrors";
|
|
41
41
|
export declare class BusinessErrors extends BaseBusinessErrors {
|
|
42
42
|
}
|
|
43
43
|
export interface FormalError extends BaseFormalError {
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import Service, {HttpRequest, HttpResponse} from "./Service";
|
|
2
2
|
import ServiceRest from "./ServiceRest";
|
|
3
|
+
import {FormalError} from "../business/BusinessErrors";
|
|
3
4
|
|
|
4
5
|
export interface Wrapper<T> {
|
|
5
6
|
code: string,
|
|
6
7
|
description: string,
|
|
7
8
|
data?: T
|
|
8
|
-
|
|
9
|
+
degug?: string
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export default class ServiceRestFormal<Req=any, Res=any> extends ServiceRest<Req, Wrapper<Res>>
|
|
@@ -21,8 +22,8 @@ export default class ServiceRestFormal<Req=any, Res=any> extends ServiceRest<Req
|
|
|
21
22
|
let content: Wrapper<Res> = ({ code: "0", description: "Service execution OK", data: response.content })
|
|
22
23
|
return Object.assign({} as HttpResponse<Wrapper<Res>>, response, {content});
|
|
23
24
|
} catch (error: any) {
|
|
24
|
-
|
|
25
|
-
throw error
|
|
25
|
+
if (error instanceof FormalError) throw error;
|
|
26
|
+
else throw new FormalError({ code: "-1", description: "Internal server error", debug: error.message })
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -1,30 +1,37 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
id
|
|
1
|
+
export interface ErrorType {
|
|
2
|
+
id?: string;
|
|
3
3
|
code: string;
|
|
4
4
|
description: string;
|
|
5
5
|
httpCode?: number;
|
|
6
6
|
group?: string;
|
|
7
|
+
debug?: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class FormalError extends Error {
|
|
11
|
+
type: ErrorType;
|
|
12
|
+
constructor(type: ErrorType) {
|
|
13
|
+
super(); this.type = type;
|
|
14
|
+
}
|
|
7
15
|
}
|
|
8
16
|
|
|
9
17
|
export default class BusinessErrors {
|
|
10
18
|
|
|
11
|
-
private errors: { [key: string]:
|
|
19
|
+
private errors: { [key: string]: ErrorType } = {};
|
|
12
20
|
|
|
13
21
|
async init() { }
|
|
14
22
|
|
|
15
|
-
setErrors(errors: { [key: string]:
|
|
23
|
+
setErrors(errors: { [key: string]: ErrorType }) {
|
|
16
24
|
this.errors = errors;
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
get(code: string, ...params: string[]) {
|
|
20
28
|
let error = this.errors[code] ?? this.getFallback();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return result;
|
|
29
|
+
for (const p in params) error.description = error.description?.replace(`\${${p}}`, params[p])
|
|
30
|
+
return error;
|
|
24
31
|
}
|
|
25
32
|
|
|
26
|
-
except(code: string, ...params: string[]) {
|
|
27
|
-
let error = this.get(code, ...params)
|
|
33
|
+
except(code: string, ...params: string[]): never {
|
|
34
|
+
let error = new FormalError(this.get(code, ...params))
|
|
28
35
|
//this.onExcept?.(error)
|
|
29
36
|
throw error;
|
|
30
37
|
}
|
|
@@ -95,7 +102,7 @@ export default class BusinessErrors {
|
|
|
95
102
|
return new Date(value);
|
|
96
103
|
}
|
|
97
104
|
|
|
98
|
-
getFallback():
|
|
105
|
+
getFallback(): ErrorType {
|
|
99
106
|
return { id: "-1", description: "Internal Server error", code: "-1", httpCode: 500 };
|
|
100
107
|
}
|
|
101
108
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Service, {HttpRequest, HttpResponse} from "../api/Service";
|
|
2
2
|
import Business from "./Business";
|
|
3
|
+
import {FormalError} from "../business/BusinessErrors";
|
|
3
4
|
|
|
4
5
|
export default class BusinessServer extends Business
|
|
5
6
|
{
|
|
@@ -89,6 +90,7 @@ export default class BusinessServer extends Business
|
|
|
89
90
|
} catch (error: any) {
|
|
90
91
|
try { error = this.onError?.(request, error); } catch (e) { }
|
|
91
92
|
if (error instanceof HttpResponse) response = error;
|
|
93
|
+
if (error instanceof FormalError) response = error.type;
|
|
92
94
|
else response = HttpResponse.ko(error.httpCode ?? 500, error.content);
|
|
93
95
|
|
|
94
96
|
} finally {
|
package/src/main/node/index.ts
CHANGED
|
@@ -34,7 +34,7 @@ export class BusinessServer extends _BusinessServer {}
|
|
|
34
34
|
import BaseBusinessThread from "./business/BusinessThread";
|
|
35
35
|
export abstract class BusinessThread extends BaseBusinessThread {}
|
|
36
36
|
|
|
37
|
-
import BaseBusinessErrors, {
|
|
37
|
+
import BaseBusinessErrors, { ErrorType as BaseFormalError } from "./business/BusinessErrors";
|
|
38
38
|
export class BusinessErrors extends BaseBusinessErrors {}
|
|
39
39
|
export interface FormalError extends BaseFormalError {}
|
|
40
40
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import RepositoryRest, {RestOptions} from "./RepositoryRest";
|
|
2
2
|
import {Wrapper} from "../api/ServiceRestFormal";
|
|
3
3
|
import {HttpRequest} from "../api/Service";
|
|
4
|
-
import {
|
|
4
|
+
import {FormalError} from "../business/BusinessErrors";
|
|
5
5
|
|
|
6
6
|
export default class RepositoryRestFormal<Body=any, S=any> extends RepositoryRest<Body, Wrapper<S>> {
|
|
7
7
|
|
|
@@ -20,13 +20,12 @@ export default class RepositoryRestFormal<Body=any, S=any> extends RepositoryRes
|
|
|
20
20
|
let content = response.content;
|
|
21
21
|
if (content) {
|
|
22
22
|
if (content.code === "0") return content.data;
|
|
23
|
-
else throw { code: content.code, description: content.description };
|
|
24
|
-
} else throw { code: "-1", description: "Not formal response" };
|
|
23
|
+
else throw new FormalError({ code: content.code, description: content.description });
|
|
24
|
+
} else throw new FormalError({ code: "-1", description: "Not formal response" });
|
|
25
25
|
})
|
|
26
26
|
.catch((error) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
throw { code: "-1", description: "ConnectionError", error: error.message };
|
|
27
|
+
if (error instanceof FormalError) throw error;
|
|
28
|
+
else throw new FormalError({ code: "-1", description: "ConnectionError", debug: error.message });
|
|
30
29
|
});
|
|
31
30
|
}
|
|
32
31
|
}
|