UNPKG

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