import axios from 'axios';
import Fetch from './Fetch.types';
const instance = axios.create({
  baseURL: process.env.REACT_APP_API_URL,
  timeout: undefined,
});

class FetchAxios implements Fetch {
  baseurl: string = '';
  constructor(config: { baseurl: string }) {
    this.baseurl = config.baseurl;
  }
  async get(url: string) {
    try {
      const response = await instance.get(this.baseurl + url);
      if (response?.status === 200 || response?.status === 201) {
        return response.data;
      } else throw new Error('Status different from 200 or 201');
    } catch (e) {
      throw new Error(`Something went wrong ${e}`);
    }
  }
}
export default FetchAxios;
