const fetch = (url, option) => new Promise((resolve, reject) => {
  option = option || {};
  if (option.headers === undefined) {
    option.headers = { 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8' };
  }
  window.fetch(url, option).then((response) => {
    if (!response.ok) {
      throw new Error();
    }
    return response.json();
  }).then((data) => {
    resolve(data);
  }).catch((err) => {
    reject(err);
  });
});

export default fetch;
