Skip to content

Commit 6b7efd1

Browse files
committed
- Removed need for abort controller in axios implementation
- Fixed export of cancelable promise for custom requests -
1 parent ad11e63 commit 6b7efd1

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ module.exports = {
2020
testMatch: [
2121
'<rootDir>/test/e2e/v2.fetch.spec.js',
2222
'<rootDir>/test/e2e/v2.xhr.spec.js',
23-
'<rootDir>/test/e2e/v2.axios.spec.js',
2423
'<rootDir>/test/e2e/v2.node.spec.js',
24+
'<rootDir>/test/e2e/v2.axios.spec.js',
2525
'<rootDir>/test/e2e/v2.babel.spec.js',
2626
'<rootDir>/test/e2e/v3.fetch.spec.js',
2727
'<rootDir>/test/e2e/v3.xhr.spec.js',
28-
'<rootDir>/test/e2e/v3.axios.spec.js',
2928
'<rootDir>/test/e2e/v3.node.spec.js',
29+
'<rootDir>/test/e2e/v3.axios.spec.js',
3030
'<rootDir>/test/e2e/v3.babel.spec.js',
3131
],
3232
},

src/templates/core/axios/request.hbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{{>header}}
22

3-
import { AbortController } from 'abort-controller';
43
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
54
import FormData from 'form-data';
65

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
async function sendRequest(options: ApiRequestOptions, url: string, onCancel: (cancelHandler: () => void) => void): Promise<AxiosResponse<any>> {
2-
const controller = new AbortController();
2+
const source = axios.CancelToken.source();
33
const formData = options.formData && getFormData(options.formData);
44
const data = formData || options.body;
55

@@ -8,10 +8,10 @@ async function sendRequest(options: ApiRequestOptions, url: string, onCancel: (c
88
data,
99
method: options.method,
1010
headers: await getHeaders(options, formData),
11-
signal: controller.signal,
11+
cancelToken: source.token,
1212
};
1313

14-
onCancel(() => controller.abort());
14+
onCancel(() => source.cancel('The user aborted a request.'));
1515

1616
return await axios.request(config);
1717
}

src/templates/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{#if @root.exportCore}}
33

44
export { ApiError } from './core/ApiError';
5-
export type { CancelablePromise } from './core/CancelablePromise';
5+
export { CancelablePromise } from './core/CancelablePromise';
66
export { OpenAPI } from './core/OpenAPI';
77
{{/if}}
88
{{#if @root.exportModels}}

test/__snapshots__/index.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ exports[`v2 should generate: ./test/generated/v2/index.ts 1`] = `
430430
/* tslint:disable */
431431
/* eslint-disable */
432432
export { ApiError } from './core/ApiError';
433-
export type { CancelablePromise } from './core/CancelablePromise';
433+
export { CancelablePromise } from './core/CancelablePromise';
434434
export { OpenAPI } from './core/OpenAPI';
435435

436436
export type { ArrayWithArray } from './models/ArrayWithArray';
@@ -2899,7 +2899,7 @@ exports[`v3 should generate: ./test/generated/v3/index.ts 1`] = `
28992899
/* tslint:disable */
29002900
/* eslint-disable */
29012901
export { ApiError } from './core/ApiError';
2902-
export type { CancelablePromise } from './core/CancelablePromise';
2902+
export { CancelablePromise } from './core/CancelablePromise';
29032903
export { OpenAPI } from './core/OpenAPI';
29042904

29052905
export type { ArrayWithArray } from './models/ArrayWithArray';

test/e2e/v2.axios.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('v2.node', () => {
4545
}, 10);
4646
await promise;
4747
} catch (e) {
48-
expect(e.message).toContain('canceled');
48+
expect(e.message).toContain('The user aborted a request.');
4949
}
5050
});
5151
});

test/e2e/v3.axios.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('v3.node', () => {
6464
}, 10);
6565
await promise;
6666
} catch (e) {
67-
expect(e.message).toContain('canceled');
67+
expect(e.message).toContain('The user aborted a request.');
6868
}
6969
});
7070
});

0 commit comments

Comments
 (0)