@@ -27,60 +27,81 @@ export const getAxios = async (force: boolean = false): Promise<AxiosInstance> =
27
27
28
28
export async function mihomoVersion ( ) : Promise < IMihomoVersion > {
29
29
const instance = await getAxios ( )
30
- return instance . get ( '/version' ) as Promise < IMihomoVersion >
30
+ return instance . get ( '/version' ) . catch ( ( e ) => {
31
+ return e . response . data
32
+ } )
31
33
}
32
34
33
35
export const mihomoConfig = async ( ) : Promise < IMihomoConfig > => {
34
36
const instance = await getAxios ( )
35
- return instance . get ( '/configs' ) as Promise < IMihomoConfig >
37
+ return instance . get ( '/configs' ) . catch ( ( e ) => {
38
+ return e . response . data
39
+ } )
36
40
}
37
41
38
42
export const patchMihomoConfig = async ( patch : Partial < IMihomoConfig > ) : Promise < void > => {
39
43
const instance = await getAxios ( )
40
- return instance . patch ( '/configs' , patch )
44
+ return instance . patch ( '/configs' , patch ) . catch ( ( e ) => {
45
+ return e . response . data
46
+ } )
41
47
}
42
48
43
49
export const mihomoConnections = async ( ) : Promise < IMihomoConnectionsInfo > => {
44
50
const instance = await getAxios ( )
45
- return instance . get ( '/connections' ) as Promise < IMihomoConnectionsInfo >
51
+ return instance . get ( '/connections' ) . catch ( ( e ) => {
52
+ return e . response . data
53
+ } )
46
54
}
47
55
48
56
export const mihomoCloseConnection = async ( id : string ) : Promise < void > => {
49
57
const instance = await getAxios ( )
50
- return instance . delete ( `/connections/${ encodeURIComponent ( id ) } ` )
58
+ return instance . delete ( `/connections/${ encodeURIComponent ( id ) } ` ) . catch ( ( e ) => {
59
+ return e . response . data
60
+ } )
51
61
}
52
62
53
63
export const mihomoCloseAllConnections = async ( ) : Promise < void > => {
54
64
const instance = await getAxios ( )
55
- return instance . delete ( '/connections' )
65
+ return instance . delete ( '/connections' ) . catch ( ( e ) => {
66
+ return e . response . data
67
+ } )
56
68
}
57
69
58
70
export const mihomoRules = async ( ) : Promise < IMihomoRulesInfo > => {
59
71
const instance = await getAxios ( )
60
- return instance . get ( '/rules' ) as Promise < IMihomoRulesInfo >
72
+ return instance . get ( '/rules' ) . catch ( ( e ) => {
73
+ return e . response . data
74
+ } )
61
75
}
62
76
63
77
export const mihomoProxies = async ( ) : Promise < IMihomoProxies > => {
64
78
const instance = await getAxios ( )
65
- return instance . get ( '/proxies' ) as Promise < IMihomoProxies >
79
+ return instance . get ( '/proxies' ) . catch ( ( e ) => {
80
+ return e . response . data
81
+ } )
66
82
}
67
83
68
84
export const mihomoChangeProxy = async ( group : string , proxy : string ) : Promise < IMihomoProxy > => {
69
85
const instance = await getAxios ( )
70
- return instance . put ( `/proxies/${ encodeURIComponent ( group ) } ` , { name : proxy } )
86
+ return instance . put ( `/proxies/${ encodeURIComponent ( group ) } ` , { name : proxy } ) . catch ( ( e ) => {
87
+ return e . response . data
88
+ } )
71
89
}
72
90
73
91
export const mihomoProxyDelay = async ( proxy : string , url ?: string ) : Promise < IMihomoDelay > => {
74
92
const appConfig = getAppConfig ( )
75
93
const { delayTestUrl, delayTestTimeout } = appConfig
76
94
const instance = await getAxios ( )
77
- return instance . get ( `/proxies/${ encodeURIComponent ( proxy ) } /delay` , {
78
- params : {
79
- url : url || delayTestUrl || 'https://www.gstatic.com/generate_204' ,
80
- timeout : delayTestTimeout || 5000
81
- } ,
82
- timeout : delayTestTimeout || 5000
83
- } )
95
+ return instance
96
+ . get ( `/proxies/${ encodeURIComponent ( proxy ) } /delay` , {
97
+ params : {
98
+ url : url || delayTestUrl || 'https://www.gstatic.com/generate_204' ,
99
+ timeout : delayTestTimeout || 5000
100
+ }
101
+ } )
102
+ . catch ( ( e ) => {
103
+ return e . response . data
104
+ } )
84
105
}
85
106
86
107
export const startMihomoTraffic = ( ) : void => {
0 commit comments