@gopowerteam/request 0.1.5 → 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/dist/adapters/index.cjs +12 -3
- package/dist/adapters/index.d.ts +10 -4
- package/dist/adapters/index.js +10 -1
- package/dist/{chunk-QZESQRIV.js → chunk-BKQFIRDI.js} +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{request-adapter.interface-f0b0f677.d.ts → request-adapter.interface-bd32c0be.d.ts} +6 -1
- package/package.json +1 -1
package/dist/adapters/index.cjs
CHANGED
|
@@ -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).
|
|
114
|
+
const response = await this.startRequest(adapter, options).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
|
|
115
115
|
hasException = true;
|
|
116
|
-
return
|
|
117
|
-
})
|
|
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");
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
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<
|
|
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:
|
|
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 };
|
package/dist/adapters/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RequestService,
|
|
3
3
|
__publicField
|
|
4
|
-
} from "../chunk-
|
|
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).
|
|
89
|
+
const response = await this.startRequest(adapter, options).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
|
|
90
90
|
hasException = true;
|
|
91
|
-
return
|
|
92
|
-
})
|
|
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).
|
|
116
|
+
const response = await this.startRequest(adapter, options).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
|
|
117
117
|
hasException = true;
|
|
118
|
-
return
|
|
119
|
-
})
|
|
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-
|
|
2
|
-
export { A as AdapterResponse, a as RequestAdapter, b as RequestAdapterOptions, c as RequestMethod, R as RequestSendOptions } from './request-adapter.interface-
|
|
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
package/dist/{request-adapter.interface-f0b0f677.d.ts → request-adapter.interface-bd32c0be.d.ts}
RENAMED
|
@@ -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 };
|