import fetch from 'isomorphic-fetch'

import config from './config'


async function fetchJson(url, options) {
  const response = await fetch(url, options)
  if (response.status < 200 || response.status >= 300) {
    throw new Error(`'${url}' returned the unexpected return code: '${response.status}'.`)
  }
  const data = await response.json()
  return {
    data,
    'country-package': response.headers.get('country-package'),
    'country-package-version': response.headers.get('country-package-version'),
  }
}


export function fetchParameters(apiBaseUrl = config.apiBaseUrl) {
  return fetchJson(`${apiBaseUrl}/parameters`)
}

export function fetchVariables(apiBaseUrl = config.apiBaseUrl) {
  return fetchJson(`${apiBaseUrl}/variables`)
}

export function fetchParameter(parameterId, apiBaseUrl = config.apiBaseUrl) {
  return fetchJson(`${apiBaseUrl}/parameter/${parameterId}`)
}

export function fetchVariable(variableId, apiBaseUrl = config.apiBaseUrl) {
  return fetchJson(`${apiBaseUrl}/variable/${variableId}`)
}

export function fetchSwagger(apiBaseUrl = config.apiBaseUrl) {
  return fetchJson(`${apiBaseUrl}/spec`)
}

@@ -149,16 +149,82 @@
 ptions)%0A
+    .catch(() =%3E %7B throw new Error(%60Could not fetch '$%7Burl%7D'.%60)%7D)%0A
   if (re

Improve error is API is dead