Skip to content

Commit ba2c277

Browse files
committed
Fix of axios@1.1.3 bug
- details: axios/axios#5154 - prettier line width 80 >> 100
1 parent 7713040 commit ba2c277

File tree

4 files changed

+24
-48
lines changed

4 files changed

+24
-48
lines changed

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"bracketSpacing": true,
44
"jsxBracketSameLine": false,
55
"jsxSingleQuote": true,
6-
"printWidth": 80,
6+
"printWidth": 100,
77
"semi": true,
88
"singleQuote": true,
99
"tabWidth": 2,

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@types/jest": "^29.2.0",
4444
"@typescript-eslint/eslint-plugin": "^5.40.1",
4545
"@typescript-eslint/parser": "^5.40.1",
46-
"axios": "^1.1.3",
46+
"axios": "^1.2.0-alpha.1",
4747
"eslint": "^8.26.0",
4848
"husky": "^8.0.1",
4949
"jest": "^29.2.1",

src/index.ts

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
import axios, {
2-
AxiosInstance,
3-
AxiosRequestConfig,
4-
AxiosResponse,
5-
AxiosDefaults,
6-
} from 'axios';
7-
8-
export type MethodName =
9-
| 'get'
10-
| 'delete'
11-
| 'head'
12-
| 'options'
13-
| 'post'
14-
| 'put'
15-
| 'patch';
1+
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosDefaults } from 'axios';
2+
3+
export type MethodName = 'get' | 'delete' | 'head' | 'options' | 'post' | 'put' | 'patch';
164

175
export interface Next<R> {
186
(config: AxiosRequestConfig): Promise<AxiosResponse<R>>;
@@ -44,11 +32,7 @@ export interface AxiosInstanceWrapper {
4432
const ArgsToConfig = {
4533
withBody: (
4634
method: MethodName,
47-
[url, data, config]: [
48-
url?: string,
49-
data?: any,
50-
config?: AxiosRequestConfig,
51-
],
35+
[url, data, config]: [url?: string, data?: any, config?: AxiosRequestConfig],
5236
): AxiosRequestConfig => ({
5337
url,
5438
method,
@@ -65,9 +49,7 @@ const ArgsToConfig = {
6549
}),
6650
};
6751

68-
export const create = (
69-
instanceConfig: AxiosRequestConfig,
70-
): AxiosInstanceWrapper => {
52+
export function create(instanceConfig: AxiosRequestConfig): AxiosInstanceWrapper {
7153
const instance = axios.create(instanceConfig);
7254

7355
let request = instance.request.bind(instance);
@@ -84,14 +66,10 @@ export const create = (
8466
patch: (...args) => request(ArgsToConfig.withBody('patch', args)),
8567
};
8668

87-
const useMiddleware = <M>(
88-
middleware: Middleware<M>,
89-
): AxiosInstanceWrapper => {
69+
const useMiddleware = <M>(middleware: Middleware<M>): AxiosInstanceWrapper => {
9070
const wrapped = request;
9171

92-
request = async function <T = any, R = AxiosResponse<T>>(
93-
requestConfig: AxiosRequestConfig,
94-
) {
72+
request = async function <T = any, R = AxiosResponse<T>>(requestConfig: AxiosRequestConfig) {
9573
let promise: Promise<R> | undefined;
9674

9775
await middleware(
@@ -106,9 +84,7 @@ export const create = (
10684
);
10785

10886
if (!promise) {
109-
throw Error(
110-
'Looks like one of your middleware functions is not called "next"',
111-
);
87+
throw Error('Looks like one of your middleware functions is not called "next"');
11288
}
11389

11490
// IMPORTANT: returns original promise here and don`t create another
@@ -125,4 +101,4 @@ export const create = (
125101
};
126102

127103
return wrapper;
128-
};
104+
}

0 commit comments

Comments
 (0)