React App: EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection

Viewed 5073

Refactoring my app to use a new price API and I'm getting the following error:

EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection.

The free API doc for /currencies/ticker http://docs.nomics.com/#tag/Currencies

Here is my code after I added 'Content-type': 'text/event-stream'

const headers: IHeaders = {
  baseURL: NOMICS_API_BASE_URL, // 'https://api.nomics.com/v1/'
  headers: {
    'Content-Type': 'text/event-stream'
  },
  params: {
    key: NOMICS_KEY
  }
}

// * GET Currencies
export const getCurrenciesRequest = async () => {
  console.log('getCurrenciesRequest...')
  const nomics = axios.create(headers)

  try {
    const currencies = await nomics.get(`currencies/ticker&ids=BTC,ETH,XRP&interval=1d,30d&convert=USD`)
    console.log('currencies', currencies)
    return currencies
  } catch (err) {
    return err
  }
}

Also just tried

const currencies = await axios.get(`https://api.nomics.com/v1/currencies/ticker?key=demo-26240835858194712a4f8cc0dc635c7a&ids=BTC,ETH,XRP&interval=1d,30d&convert=USD`)

and lower cased key 'content-type': 'text/event-stream'

Not sure what I'm missing, hoping for some thoughts here...

UPDATE

I am able to get the response back now by removing axios.create(headers)

export const getCurrenciesRequest = async () => {
  console.log('getCurrenciesRequest...')

  try {
    const currencies = await axios.get(`https://api.nomics.com/v1/currencies/ticker?key=demo-26240835858194712a4f8cc0dc635c7a&ids=BTC,ETH,XRP&interval=1d,30d&convert=USD`)
    console.log('currencies', currencies)
    return currencies
  } catch (err) {
    return err
  }
}

However I still get the same error

EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection.

enter image description here

1 Answers
Related