cerebral-legacy / cerebral-module-http

HTTP module for Cerebral

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onResponse returns json even though the header might not be json

edgesoft opened this issue · comments

We need to look at the actual response to make sure it's not just text. If we make a request to an api endpoint that does not exists it returns a String and will be Uncaught SyntaxError when parsed as json.

I believe I fixed that?

    var result = xhr.responseText

    if (xhr.getResponseHeader('content-type').indexOf('application/json') >= 0) {
      result = JSON.parse(xhr.responseText)
    }

:)