Skip to content

Commit 3771576

Browse files
committed
Don't parse JSON files as actual JSON
1 parent 0f8dcab commit 3771576

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import http from "@/api/http";
2+
import {AxiosError} from "axios";
23

34
export default (server: string, file: string): Promise<string> => {
45
return new Promise((resolve, reject) => {
56
http.get(`/api/client/servers/${server}/files/contents`, {
6-
params: { file }
7+
params: { file },
8+
responseType: 'text',
9+
transformResponse: res => res,
710
})
8-
.then(response => resolve(response.data))
9-
.catch(reject);
11+
.then(response => resolve(response.data || ''))
12+
.catch((error: AxiosError) => {
13+
if (error.response && error.response.data) {
14+
error.response.data = JSON.parse(error.response.data);
15+
}
16+
17+
reject(error);
18+
});
1019
});
1120
}

0 commit comments

Comments
 (0)