{"size": 660, "ext": "js", "max_stars_repo_path": "client/src/util/fetch.js", "max_stars_repo_name": "plievone/horizon", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/util/fetch.js", "max_issues_repo_name": "plievone/horizon", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/src/util/fetch.js", "max_forks_repo_name": "plievone/horizon", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.0, "max_line_length": 74, "alphanum_fraction": 0.6560606061}
import { Observable } from 'rxjs/Observable'
import 'rxjs/add/observable/fromPromise'
import 'rxjs/add/operator/mergeMap'

global.self = global
require('imports?this=>global!exports?global.fetch!isomorphic-fetch')

export default function fetchJSON(url) {
  return Observable.fromPromise(fetch(url))
    .mergeMap(response => {
      const contentType = response.headers.get('content-type')
      if (contentType && contentType.indexOf('application/json') !== -1) {
        return response.json()
      } else {
        return response.text().then(resp => ({
          error: 'Response was not json',
          responseBody: resp,
        }))
      }
    })
}
