fetchOrThrow.js 795 B

123456789101112131415161718192021
  1. import { __awaiter, __generator } from "tslib";
  2. import { env } from '../env';
  3. export function fetchOrThrow(url, init) {
  4. return __awaiter(this, void 0, void 0, function () {
  5. var fetch, res;
  6. return __generator(this, function (_a) {
  7. switch (_a.label) {
  8. case 0:
  9. fetch = env.getEnv().fetch;
  10. return [4 /*yield*/, fetch(url, init)];
  11. case 1:
  12. res = _a.sent();
  13. if (!(res.status < 400)) {
  14. throw new Error("failed to fetch: (" + res.status + ") " + res.statusText + ", from url: " + res.url);
  15. }
  16. return [2 /*return*/, res];
  17. }
  18. });
  19. });
  20. }
  21. //# sourceMappingURL=fetchOrThrow.js.map