@gopowerteam/request 0.1.4 → 0.1.6

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/adapters.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/adapters/index.d'
@@ -111,10 +111,10 @@ var _RequestService = class {
111
111
  let hasException = false;
112
112
  const adapter = this.getRequestAdapter();
113
113
  this.execRequestPlugin(plugins, options);
114
- const response = await this.startRequest(adapter, options).catch((...response2) => {
114
+ const response = await this.startRequest(adapter, options).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
115
115
  hasException = true;
116
- return response2;
117
- }).then((response2) => adapter.transformResponse(response2));
116
+ return adapter.transformException(exception);
117
+ });
118
118
  if (!hasException) {
119
119
  this.execResponsePlugin("after" /* after */, plugins, options, response);
120
120
  } else {
@@ -166,6 +166,15 @@ var _AxiosAdapter = class {
166
166
  headers: response.headers
167
167
  };
168
168
  }
169
+ transformException(exception) {
170
+ var _a, _b, _c, _d;
171
+ return {
172
+ data: ((_a = exception.response) == null ? void 0 : _a.data) || {},
173
+ statusText: ((_b = exception.response) == null ? void 0 : _b.statusText) || "",
174
+ status: ((_c = exception.response) == null ? void 0 : _c.status) || 400,
175
+ headers: ((_d = exception.response) == null ? void 0 : _d.headers) || {}
176
+ };
177
+ }
169
178
  };
170
179
  var AxiosAdapter = _AxiosAdapter;
171
180
  __publicField(AxiosAdapter, "axiosInstance");
@@ -1,5 +1,5 @@
1
- import * as axios from 'axios';
2
- import { a as RequestAdapter, b as RequestAdapterOptions, A as AdapterResponse } from '../request-adapter.interface-f0b0f677.js';
1
+ import { a as RequestAdapter, b as RequestAdapterOptions, A as AdapterResponse } from '../request-adapter.interface-bd32c0be.js';
2
+ import { AxiosResponse, AxiosError } from 'axios';
3
3
 
4
4
  declare class AxiosAdapter implements RequestAdapter {
5
5
  private static axiosInstance;
@@ -12,13 +12,19 @@ declare class AxiosAdapter implements RequestAdapter {
12
12
  * @param options 请求参数
13
13
  * @returns AxiosResponse
14
14
  */
15
- request({ baseURL, pathURL, headers, method, paramsQuery, paramsBody }: RequestAdapterOptions): Promise<axios.AxiosResponse<any, any>>;
15
+ request({ baseURL, pathURL, headers, method, paramsQuery, paramsBody }: RequestAdapterOptions): Promise<AxiosResponse<any, any>>;
16
16
  /**
17
17
  * 转换Response
18
18
  * @param response
19
19
  * @returns
20
20
  */
21
- transformResponse(response: any): AdapterResponse;
21
+ transformResponse(response: AxiosResponse): AdapterResponse;
22
+ /**
23
+ * 转换Response
24
+ * @param response
25
+ * @returns
26
+ */
27
+ transformException(exception: AxiosError): AdapterResponse;
22
28
  }
23
29
 
24
30
  export { AxiosAdapter };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  RequestService,
3
3
  __publicField
4
- } from "../chunk-QZESQRIV.js";
4
+ } from "../chunk-BKQFIRDI.js";
5
5
 
6
6
  // src/adapters/axios.adapter.ts
7
7
  import axios from "axios";
@@ -43,6 +43,15 @@ var _AxiosAdapter = class {
43
43
  headers: response.headers
44
44
  };
45
45
  }
46
+ transformException(exception) {
47
+ var _a, _b, _c, _d;
48
+ return {
49
+ data: ((_a = exception.response) == null ? void 0 : _a.data) || {},
50
+ statusText: ((_b = exception.response) == null ? void 0 : _b.statusText) || "",
51
+ status: ((_c = exception.response) == null ? void 0 : _c.status) || 400,
52
+ headers: ((_d = exception.response) == null ? void 0 : _d.headers) || {}
53
+ };
54
+ }
46
55
  };
47
56
  var AxiosAdapter = _AxiosAdapter;
48
57
  __publicField(AxiosAdapter, "axiosInstance");
@@ -86,10 +86,10 @@ var _RequestService = class {
86
86
  let hasException = false;
87
87
  const adapter = this.getRequestAdapter();
88
88
  this.execRequestPlugin(plugins, options);
89
- const response = await this.startRequest(adapter, options).catch((...response2) => {
89
+ const response = await this.startRequest(adapter, options).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
90
90
  hasException = true;
91
- return response2;
92
- }).then((response2) => adapter.transformResponse(response2));
91
+ return adapter.transformException(exception);
92
+ });
93
93
  if (!hasException) {
94
94
  this.execResponsePlugin("after" /* after */, plugins, options, response);
95
95
  } else {
package/dist/index.cjs CHANGED
@@ -113,10 +113,10 @@ var _RequestService = class {
113
113
  let hasException = false;
114
114
  const adapter = this.getRequestAdapter();
115
115
  this.execRequestPlugin(plugins, options);
116
- const response = await this.startRequest(adapter, options).catch((...response2) => {
116
+ const response = await this.startRequest(adapter, options).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
117
117
  hasException = true;
118
- return response2;
119
- }).then((response2) => adapter.transformResponse(response2));
118
+ return adapter.transformException(exception);
119
+ });
120
120
  if (!hasException) {
121
121
  this.execResponsePlugin("after" /* after */, plugins, options, response);
122
122
  } else {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequestSendOptions, A as AdapterResponse, a as RequestAdapter } from './request-adapter.interface-f0b0f677.js';
2
- export { A as AdapterResponse, a as RequestAdapter, b as RequestAdapterOptions, c as RequestMethod, R as RequestSendOptions } from './request-adapter.interface-f0b0f677.js';
1
+ import { R as RequestSendOptions, A as AdapterResponse, a as RequestAdapter } from './request-adapter.interface-bd32c0be.js';
2
+ export { A as AdapterResponse, a as RequestAdapter, b as RequestAdapterOptions, c as RequestMethod, R as RequestSendOptions } from './request-adapter.interface-bd32c0be.js';
3
3
  import { IStringifyOptions } from 'qs';
4
4
 
5
5
  /**
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PluginLifecycle,
3
3
  RequestService
4
- } from "./chunk-QZESQRIV.js";
4
+ } from "./chunk-BKQFIRDI.js";
5
5
 
6
6
  // src/request-setup.ts
7
7
  function setup(config) {
@@ -29,6 +29,11 @@ interface RequestAdapter {
29
29
  * @param any
30
30
  */
31
31
  transformResponse(response: any): AdapterResponse;
32
+ /**
33
+ * 转换Exception
34
+ * @param any
35
+ */
36
+ transformException(response: any): AdapterResponse;
32
37
  }
33
38
  interface RequestAdapterOptions {
34
39
  baseURL: string;
@@ -42,7 +47,7 @@ interface AdapterResponse {
42
47
  data: Record<string, any>;
43
48
  status: number;
44
49
  statusText: string;
45
- headers: Record<string, string>;
50
+ headers: Record<string, string | string[] | undefined>;
46
51
  }
47
52
 
48
53
  export { AdapterResponse as A, RequestSendOptions as R, RequestAdapter as a, RequestAdapterOptions as b, RequestMethod as c };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@gopowerteam/request",
3
3
  "private": false,
4
- "version": "0.1.4",
4
+ "version": "0.1.6",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
8
+ "adapters.d.ts",
8
9
  "README.md"
9
10
  ],
10
11
  "keywords": [