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