fetchOrThrow.js 909 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var env_1 = require("../env");
  5. function fetchOrThrow(url, init) {
  6. return tslib_1.__awaiter(this, void 0, void 0, function () {
  7. var fetch, res;
  8. return tslib_1.__generator(this, function (_a) {
  9. switch (_a.label) {
  10. case 0:
  11. fetch = env_1.env.getEnv().fetch;
  12. return [4 /*yield*/, fetch(url, init)];
  13. case 1:
  14. res = _a.sent();
  15. if (!(res.status < 400)) {
  16. throw new Error("failed to fetch: (" + res.status + ") " + res.statusText + ", from url: " + res.url);
  17. }
  18. return [2 /*return*/, res];
  19. }
  20. });
  21. });
  22. }
  23. exports.fetchOrThrow = fetchOrThrow;
  24. //# sourceMappingURL=fetchOrThrow.js.map