How to use the ky-universal.HTTPError function in ky-universal

To help you get started, we’ve selected a few ky-universal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tunnckoCore / opensource / web / pkg.tunnckocore.com / api / _utils.js View on Github external
// ! jsDelivr can response with 403 Forbidden, if over 50MB
    if (err.response && err.response.status === 403) {
      try {
        // ! so, try through UNPKG.com
        pkg = await packageJson(
          packageName,
          (x, t) => `https://unpkg.com/${x}@${t}/package.json`,
        );
      } catch (error) {
        throw new ky.HTTPError(
          `Package "${name}" not found, even through UNPKG.com!`,
        );
      }
      return pkg;
    }
    throw new ky.HTTPError(`Package "${name}" not found or loading error!`);
  }
  return pkg;
}
github ipfs / js-ipfs-http-client / src / lib / error-handler.js View on Github external
try {
    if (isJsonResponse(response)) {
      const data = await response.json()
      log(data)
      msg = data.Message || data.message
    } else {
      msg = await response.text()
    }
  } catch (err) {
    log('Failed to parse error response', err)
    // Failed to extract/parse error message from response
    msg = err.message
  }

  const error = new HTTPError(response)

  // If we managed to extract a message from the response, use it
  if (msg) {
    error.message = msg
  }

  throw error
}
github tunnckoCore / opensource / web / ghub.now.sh / api / _utils.js View on Github external
try {
    pkg = await ky
      .get(uri)
      .then((resp) => resp.text())
      .then(JSON.parse);
  } catch (err) {
    // ! jsDelivr can response with 403 Forbidden, if over 50MB
    if (err.response && err.response.status === 403) {
      try {
        // ! so, try through UNPKG.com
        pkg = await packageJson(
          packageName,
          (x, t) => `https://unpkg.com/${x}@${t}/package.json`,
        );
      } catch (error) {
        throw new ky.HTTPError(
          `Package "${name}" not found, even through UNPKG.com!`,
        );
      }
      return pkg;
    }
    throw new ky.HTTPError(`Package "${name}" not found or loading error!`);
  }
  return pkg;
}