6

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

Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
  • Did you try skipping `Content-Type` header? – Rayon Aug 29 '20 at 03:57
  • @Rayon Yes I got that error when I didn't have Content-Type or a headers object. – Leon Gaban Aug 29 '20 at 03:58
  • What is the outcome of `const currencies = await axios.get(`https://api.nomics.com/v1/currencies/ticker?key=demo-26240835858194712a4f8cc0dc635c7a&ids=BTC,ETH,XRP&interval=1d,30d&convert=USD`)`. I tried this and it worked. I guess some other global configuration is affecting/breaking this. – Rayon Aug 29 '20 at 04:00
  • Do you have any other network request where you are using `EventSource`? – Rayon Aug 29 '20 at 04:01
  • @Rayon I am able to get the response back now! Also noticed that I get the error on line 1 `http://localhost/:1` – Leon Gaban Aug 29 '20 at 04:15
  • 1
    Happy coding ;) – Rayon Aug 29 '20 at 05:34

1 Answers1

8

Are you using a CORS extension? I had this issue as well and ran across this post: SSE `this.eventSource.onmessage` call fails. Error `"EventSource's response has a MIME type ("application/json") that is not "text/event-stream"

You may need to disable the CORS extension to remove that console error.

Dharman
  • 30,962
  • 25
  • 85
  • 135
CSL
  • 96
  • 1
  • 3