service.js 1.01 KB

import { GET, POST } from '../../../libs/request';
import { API_HOST} from '../../../libs/config';

class Service {
  constructor(url = '') {
    this.url = url;
  }

  _get(path, data) {
    let method = path ? this.url + path : API_HOST;

    console.log(`request => ${data.method || method} =>`, data);
    return GET(method, data).then(result => {

      if (result.code !== 200) {
        console.error(`response => ${data.method || method} =>`, result);
      } else {
        console.log(`response => ${data.method || method} =>`, result);
      }
      return result
    });
  }

  _post(path, data) {
    let method = path ? this.url + path : API_HOST;

    console.log(`request => ${data.method || method} =>`, data);
    return POST(method, data).then(result => {

      if (result.code !== 200) {
        console.error(`response => ${data.method || method} =>`, result);
      } else {
        console.log(`response => ${data.method || method} =>`, result);
      }
      return result;
    });
  }
}

export default Service;