| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- "use strict";
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- class WebClientFetch {
- request(options) {
- return __awaiter(this, void 0, void 0, function* () {
- const fetchOptions = {
- headers: options.headers,
- method: options.method
- };
- if (options.body) {
- fetchOptions.body = options.body;
- }
- const res = yield fetch(options.url, fetchOptions);
- if (!res.ok) {
- console.error('HTTP error', res);
- throw new Error('Error ' + res.status + ' returned from ' + options.url);
- }
- // console.log('res', res);
- return res.text();
- });
- }
- requestJSON(options) {
- return __awaiter(this, void 0, void 0, function* () {
- if (!options.headers) {
- options.headers = {};
- }
- if (options.body) {
- options.headers['content-type'] = 'application/json';
- if (typeof options.body === 'object') {
- options.body = JSON.stringify(options.body);
- }
- }
- options.headers.accept = 'application/json';
- const fetchOptions = {
- headers: options.headers,
- method: options.method
- };
- if (options.formData) {
- fetchOptions.formData = options.formData;
- }
- if (options.body) {
- fetchOptions.body = options.body;
- }
- const res = yield fetch(options.url, fetchOptions);
- if (!res.ok) {
- console.error('HTTP error', res);
- throw new Error('Error ' + res.status + ' returned from ' + options.url);
- }
- // console.log('res', res);
- return res.json();
- });
- }
- }
- exports.WebClientFetch = WebClientFetch;
- //# sourceMappingURL=webclient-fetch.js.map
|