1 import axios from 'axios';
2 import {handleApiError, handleAxiosError} from './utils/http';
3 import { camelize } from "./utils/utils";
5 // const basePath = 'api/v1/btm';
7 export function serverHttp(host) {
9 this.request = function(path, body, net, method) {
11 url: this.host[net] ? `${this.host[net]}${path}`: `${this.host}${path}`,
12 method: method ? method : 'POST' ,
14 Accept: 'application/json',
21 return axios.request(config)
23 if (resp.status !== 200 || resp.data.code !== 200) {
24 throw handleApiError(resp);
25 } else if (resp.data.code === 200) {
26 return camelize(resp.data.data);
30 throw handleAxiosError(error);
35 export function http(baseUrl) {
36 this.baseUrl = baseUrl;
37 this.request = function(path, body, method) {
39 url: `${this.baseUrl}${path}`,
40 method: method ? method : 'POST' ,
42 Accept: 'application/json',
49 return axios.request(config)
51 if (resp.status !== 200 || resp.data.code !== 200) {
52 throw handleApiError(resp);
53 } else if (resp.data.code === 200) {
54 return camelize(resp.data.data);