UNPKG

@custonomy/community-sdk

Version:

Custonomy Lib for Community

34 lines 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchURL = void 0; const tslib_1 = require("tslib"); const node_fetch_1 = tslib_1.__importDefault(require("node-fetch")); function safeParseJSON(response) { return response.text() .then((body) => { if (typeof body == 'object') { if (response.status == 404) return null; return { body: body, status: response.status }; } else { if (response.status == 404 || body == null) return null; let _body = JSON.parse(body); return { body: _body, status: response.status }; } }).catch((err) => { var _a; return { body: { type: 'error', code: 999, message: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'unknown error' } }; }); } const fetchURL = (url, option) => { return (0, node_fetch_1.default)(url, option) .then(function (response) { return safeParseJSON(response); }).then(function (ret) { return ret; }); }; exports.fetchURL = fetchURL; //# sourceMappingURL=common.js.map