@napp/dti-client 4.1.4 → 4.2.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/bundler.d.ts +0 -1
- package/bundler.js +7 -39
- package/caller.js +3 -31
- package/errorhandle.d.ts +1 -0
- package/errorhandle.js +38 -0
- package/package.json +3 -2
package/bundler.d.ts
CHANGED
package/bundler.js
CHANGED
|
@@ -14,8 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.DtiClientBandler = void 0;
|
|
16
16
|
const dti_core_1 = require("@napp/dti-core");
|
|
17
|
+
const exception_1 = require("@napp/exception");
|
|
17
18
|
const cross_fetch_1 = require("cross-fetch");
|
|
18
19
|
const base64url_1 = __importDefault(require("base64url"));
|
|
20
|
+
const errorhandle_1 = require("./errorhandle");
|
|
19
21
|
class DtiClientBandler {
|
|
20
22
|
constructor(bundleMetas, builder) {
|
|
21
23
|
this.bundleMetas = bundleMetas;
|
|
@@ -67,12 +69,7 @@ class DtiClientBandler {
|
|
|
67
69
|
}
|
|
68
70
|
call() {
|
|
69
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
|
|
71
|
-
this.validate();
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
throw dti_core_1.DtiError.fromCode('validation', error);
|
|
75
|
-
}
|
|
72
|
+
this.validate();
|
|
76
73
|
let method = this.getMethod();
|
|
77
74
|
if (method === 'get') {
|
|
78
75
|
return yield this.callGet();
|
|
@@ -91,10 +88,10 @@ class DtiClientBandler {
|
|
|
91
88
|
let resp = yield (0, cross_fetch_1.fetch)(`${baseUrl}/__bundler_get__?${q}`, {
|
|
92
89
|
method: 'get', headers
|
|
93
90
|
});
|
|
94
|
-
return yield
|
|
91
|
+
return yield (0, errorhandle_1.responseHandle)(resp);
|
|
95
92
|
}
|
|
96
93
|
catch (error) {
|
|
97
|
-
throw
|
|
94
|
+
throw exception_1.Exception.from(error);
|
|
98
95
|
}
|
|
99
96
|
});
|
|
100
97
|
}
|
|
@@ -107,39 +104,10 @@ class DtiClientBandler {
|
|
|
107
104
|
let resp = yield (0, cross_fetch_1.fetch)(`${baseUrl}/__bundler_post__`, {
|
|
108
105
|
method: 'post', headers, body: JSON.stringify(param)
|
|
109
106
|
});
|
|
110
|
-
return yield
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
throw dti_core_1.DtiError.from(error);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
respHandle(resp) {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
try {
|
|
120
|
-
let resu = yield resp.text();
|
|
121
|
-
if (resp.ok) {
|
|
122
|
-
try {
|
|
123
|
-
return JSON.parse(resu);
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
throw dti_core_1.DtiError.fromCode("InvalidJSON", resu);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
let errObject = JSON.parse(resu);
|
|
131
|
-
let error = dti_core_1.DtiError.from(errObject);
|
|
132
|
-
if (error instanceof dti_core_1.DtiErrorUnknown) {
|
|
133
|
-
throw new dti_core_1.DtiError('' + resp.status, resp.statusText);
|
|
134
|
-
}
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
throw new dti_core_1.DtiErrorUnknown(resu);
|
|
139
|
-
}
|
|
107
|
+
return yield (0, errorhandle_1.responseHandle)(resp);
|
|
140
108
|
}
|
|
141
109
|
catch (error) {
|
|
142
|
-
throw
|
|
110
|
+
throw exception_1.Exception.from(error);
|
|
143
111
|
}
|
|
144
112
|
});
|
|
145
113
|
}
|
package/caller.js
CHANGED
|
@@ -17,6 +17,7 @@ const dti_core_1 = require("@napp/dti-core");
|
|
|
17
17
|
const cross_fetch_1 = require("cross-fetch");
|
|
18
18
|
const base64url_1 = __importDefault(require("base64url"));
|
|
19
19
|
const route_1 = require("./route");
|
|
20
|
+
const errorhandle_1 = require("./errorhandle");
|
|
20
21
|
class DtiClientCaller {
|
|
21
22
|
constructor(meta, builder) {
|
|
22
23
|
this.meta = meta;
|
|
@@ -88,12 +89,7 @@ class DtiClientCaller {
|
|
|
88
89
|
}
|
|
89
90
|
call(param) {
|
|
90
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
|
|
92
|
-
this.validate(param);
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
throw dti_core_1.DtiError.fromCode('validation', error);
|
|
96
|
-
}
|
|
92
|
+
this.validate(param);
|
|
97
93
|
let url = this.getUrl();
|
|
98
94
|
let query = this.getQeury(param);
|
|
99
95
|
let method = this.getMethod();
|
|
@@ -102,31 +98,7 @@ class DtiClientCaller {
|
|
|
102
98
|
let resp = yield (0, cross_fetch_1.fetch)(url + (query ? `?${query}` : ''), {
|
|
103
99
|
method, headers, body
|
|
104
100
|
});
|
|
105
|
-
|
|
106
|
-
let resu = yield resp.text();
|
|
107
|
-
if (resp.ok) {
|
|
108
|
-
try {
|
|
109
|
-
return JSON.parse(resu);
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
throw dti_core_1.DtiError.fromCode("InvalidJSON", resu);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
let errObject = JSON.parse(resu);
|
|
117
|
-
let error = dti_core_1.DtiError.from(errObject);
|
|
118
|
-
if (error instanceof dti_core_1.DtiErrorUnknown) {
|
|
119
|
-
throw new dti_core_1.DtiError('' + resp.status, resp.statusText);
|
|
120
|
-
}
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
throw new dti_core_1.DtiErrorUnknown(resu);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
throw dti_core_1.DtiError.from(error);
|
|
129
|
-
}
|
|
101
|
+
return (0, errorhandle_1.responseHandle)(resp);
|
|
130
102
|
});
|
|
131
103
|
}
|
|
132
104
|
}
|
package/errorhandle.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function responseHandle(resp: Response): Promise<any>;
|
package/errorhandle.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.responseHandle = void 0;
|
|
13
|
+
const exception_1 = require("@napp/exception");
|
|
14
|
+
function responseHandle(resp) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
let resu = yield resp.text();
|
|
18
|
+
if (resp.ok) {
|
|
19
|
+
try {
|
|
20
|
+
return resu ? JSON.parse(resu) : undefined;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw new exception_1.Exception("api response invalid json")
|
|
24
|
+
.addException(exception_1.Exception.from(error));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (resu) {
|
|
28
|
+
let errObject = JSON.parse(resu);
|
|
29
|
+
throw exception_1.Exception.from(errObject);
|
|
30
|
+
}
|
|
31
|
+
throw new exception_1.Exception(resp.statusText).setStatus(resp.status);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw exception_1.Exception.from(error);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.responseHandle = responseHandle;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napp/dti-client",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "data transaction interface client library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"author": "Farcek <farcek@gmail.com>",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@napp/
|
|
19
|
+
"@napp/exception": "^4.1.2",
|
|
20
|
+
"@napp/dti-core": "4.2.1",
|
|
20
21
|
"base64url": "latest",
|
|
21
22
|
"cross-fetch": "latest"
|
|
22
23
|
}
|