parent
968bbb775e
commit
c0ca9001d2
|
@ -270,6 +270,7 @@ export function createAdapter(platform: AxiosAdapterPlatform) {
|
|||
): AxiosAdapterBaseOptions {
|
||||
return {
|
||||
...config,
|
||||
header: config.headers,
|
||||
success(response) {
|
||||
transformResponse(response);
|
||||
config.success(response);
|
||||
|
|
|
@ -24,20 +24,16 @@ import { generateType } from './generateType';
|
|||
*/
|
||||
export function request(config: AxiosRequestConfig) {
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
const { adapter, url, method, cancelToken } = config;
|
||||
|
||||
const adapterConfig: AxiosAdapterRequestConfig = {
|
||||
...config,
|
||||
url: url!,
|
||||
...(config as AxiosAdapterRequestConfig),
|
||||
type: generateType(config),
|
||||
method: method as AxiosAdapterRequestMethod,
|
||||
success,
|
||||
fail,
|
||||
};
|
||||
|
||||
let adapterTask: AxiosAdapterPlatformTask;
|
||||
try {
|
||||
adapterTask = adapter!(adapterConfig);
|
||||
adapterTask = config.adapter!(adapterConfig);
|
||||
} catch (err) {
|
||||
fail({
|
||||
status: 400,
|
||||
|
@ -86,6 +82,7 @@ export function request(config: AxiosRequestConfig) {
|
|||
tryToggleProgressUpdate(adapterConfig, adapterTask.onProgressUpdate);
|
||||
}
|
||||
|
||||
const { cancelToken } = config;
|
||||
if (isCancelToken(cancelToken)) {
|
||||
cancelToken.onCancel((reason) => {
|
||||
if (isPlainObject(adapterTask)) {
|
||||
|
|
|
@ -81,6 +81,9 @@ describe('src/adapter/createAdapter.ts', () => {
|
|||
expect(p.request.mock.calls[0][0]).toMatchInlineSnapshot(`
|
||||
{
|
||||
"fail": [Function],
|
||||
"header": {
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
},
|
||||
"headers": {
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
},
|
||||
|
@ -109,6 +112,9 @@ describe('src/adapter/createAdapter.ts', () => {
|
|||
"id": 1,
|
||||
"user": "test",
|
||||
},
|
||||
"header": {
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
},
|
||||
"headers": {
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
},
|
||||
|
@ -126,6 +132,9 @@ describe('src/adapter/createAdapter.ts', () => {
|
|||
{
|
||||
"fail": [Function],
|
||||
"filePath": "/path/file",
|
||||
"header": {
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
},
|
||||
"headers": {
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue