import axios from 'axios';
import { Config } from 'react-native-config';
import strings from 'localization';

/*
  Base client config for your application.
  Here you can define your base url, headers,
  timeouts and middleware used for each request.
*/
const client = axios.create({
  baseURL: "",
  timeout: 100000,
  headers: { 'content-type': 'application/jsons' },
});

// Custom middleware for requests (this one just logs the error).
client.interceptors.request.use(
  config => config,
  error => {
    console.log('Failed to make request with error:');
    console.log(error);
    return Promise.reject(error);
  }
);

// Custom middleware for responses (this one just logs the error).
client.interceptors.response.use(
  response => response,
  error => {
    if (!error.response) {
      throw new Error(strings.connectionError);
    }

    console.log('Request got response with error krish:');
    console.log(error);

    return Promise.reject(error);
  }
);

export default client;
