Vyachowski/frontend-project-11

View on GitHub
src/other_utilities/fetchRssFeed.js

Summary

Maintainability
A
0 mins
Test Coverage
import axios from 'axios';
import isXMLDocument from './isXMLDocument.js';

const fetchRssFeed = (rssLink) => axios
  .get(rssLink)
  .then((response) => {
    const xmlData = response.data.contents;
    if (!isXMLDocument(xmlData)) {
      throw new Error('xmlError');
    }
    return xmlData;
  })
  .catch((error) => {
    if (error.message === 'xmlError') throw error;

    throw (error.request
      ? new Error('networkError')
      : new Error('defaultError'));
  });

export default fetchRssFeed;