UNPKG

2.01 kBJavaScriptView Raw
1var __rest = (this && this.__rest) || function (s, e) {
2 var t = {};
3 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4 t[p] = s[p];
5 if (s != null && typeof Object.getOwnPropertySymbols === "function")
6 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8 t[p[i]] = s[p[i]];
9 }
10 return t;
11};
12import axios from 'axios';
13export default class FSNetwork {
14 constructor(config) {
15 if (config) {
16 const { responseIntercept, responseError } = config, axiosConfig = __rest(config, ["responseIntercept", "responseError"]);
17 this.instance = axios.create(axiosConfig);
18 this.setInterceptor(config);
19 }
20 else {
21 this.instance = axios.create();
22 }
23 }
24 removeInterceptor() {
25 if (this.interceptor !== undefined) {
26 this.instance.interceptors.response.eject(this.interceptor);
27 this.interceptor = undefined;
28 }
29 }
30 setInterceptor(config) {
31 this.removeInterceptor();
32 if (config && (config.responseIntercept || config.responseError)) {
33 this.interceptor = this.instance.interceptors.response.use(config.responseIntercept, config.responseError);
34 }
35 }
36 request(config) {
37 return this.instance.request(config);
38 }
39 get(uri, config) {
40 return this.instance.get(uri, config);
41 }
42 delete(uri, config) {
43 return this.instance.delete(uri, config);
44 }
45 head(uri, config) {
46 return this.instance.head(uri, config);
47 }
48 post(uri, data, config) {
49 return this.instance.post(uri, data, config);
50 }
51 put(uri, data, config) {
52 return this.instance.put(uri, data, config);
53 }
54 patch(uri, data, config) {
55 return this.instance.patch(uri, data, config);
56 }
57}
58//# sourceMappingURL=index.js.map
\No newline at end of file