@napp/dti-client 4.2.3 → 4.3.3

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/caller.d.ts CHANGED
@@ -15,4 +15,5 @@ export declare class DtiClientCaller<RESULT, PARAM> {
15
15
  private getUrl;
16
16
  bundler(param: PARAM): BundleMeta<RESULT, PARAM>;
17
17
  call(param: PARAM): Promise<RESULT>;
18
+ callRaw(param: PARAM): Promise<Response>;
18
19
  }
package/caller.js CHANGED
@@ -87,6 +87,12 @@ class DtiClientCaller {
87
87
  return { meta: this.meta, param };
88
88
  }
89
89
  call(param) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ let resp = yield this.callRaw(param);
92
+ return yield (0, errorhandle_1.responseHandle)(resp);
93
+ });
94
+ }
95
+ callRaw(param) {
90
96
  return __awaiter(this, void 0, void 0, function* () {
91
97
  this.validate(param);
92
98
  let url = this.getUrl();
@@ -94,10 +100,9 @@ class DtiClientCaller {
94
100
  let method = this.getMethod();
95
101
  let headers = this.getHeaders(param);
96
102
  let body = this.getBody(param);
97
- let resp = yield (0, cross_fetch_1.fetch)(url + (query ? `?${query}` : ''), {
103
+ return yield (0, cross_fetch_1.fetch)(url + (query ? `?${query}` : ''), {
98
104
  method, headers, body
99
105
  });
100
- return (0, errorhandle_1.responseHandle)(resp);
101
106
  });
102
107
  }
103
108
  }
package/errorhandle.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function responseHandle(resp: Response): Promise<any>;
1
+ export declare function responseHandle<T>(resp: Response): Promise<T>;
package/errorhandle.js CHANGED
@@ -14,21 +14,37 @@ const exception_1 = require("@napp/exception");
14
14
  function responseHandle(resp) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
16
  try {
17
- let resu = yield resp.text();
17
+ let rsu = yield resp.text();
18
18
  if (resp.ok) {
19
+ if (rsu) {
20
+ try {
21
+ let value = JSON.parse(rsu);
22
+ return value;
23
+ }
24
+ catch (error) {
25
+ throw new exception_1.Exception(rsu, {
26
+ name: exception_1.ExceptionNames.Server,
27
+ });
28
+ }
29
+ }
30
+ return void 0;
31
+ }
32
+ if (rsu) {
33
+ let err;
19
34
  try {
20
- return resu ? JSON.parse(resu) : undefined;
35
+ let errObject = JSON.parse(rsu);
36
+ err = exception_1.Exception.from(errObject);
21
37
  }
22
38
  catch (error) {
23
- throw new exception_1.Exception("api response invalid json")
24
- .addException(exception_1.Exception.from(error));
39
+ err = new exception_1.Exception(rsu, {
40
+ name: exception_1.ExceptionNames.Server,
41
+ });
25
42
  }
43
+ throw err;
26
44
  }
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);
45
+ throw new exception_1.Exception(`status=${resp.status}. ${resp.statusText}`, {
46
+ name: exception_1.ExceptionNames.Server,
47
+ });
32
48
  }
33
49
  catch (error) {
34
50
  throw exception_1.Exception.from(error);
package/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export * from './caller';
3
3
  export * from './client';
4
4
  export * from './route';
5
5
  export * from './tree';
6
+ export * from './errorhandle';
package/index.js CHANGED
@@ -19,3 +19,4 @@ __exportStar(require("./caller"), exports);
19
19
  __exportStar(require("./client"), exports);
20
20
  __exportStar(require("./route"), exports);
21
21
  __exportStar(require("./tree"), exports);
22
+ __exportStar(require("./errorhandle"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napp/dti-client",
3
- "version": "4.2.3",
3
+ "version": "4.3.3",
4
4
  "description": "data transaction interface client library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,8 +16,8 @@
16
16
  "author": "Farcek <farcek@gmail.com>",
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
- "@napp/exception": "^4.1.2",
20
- "@napp/dti-core": "4.2.3",
19
+ "@napp/exception": "^5.1.7",
20
+ "@napp/dti-core": "4.3.3",
21
21
  "cross-fetch": "latest"
22
22
  }
23
23
  }