@ywfe/fe-tools 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -8359,29 +8359,29 @@ var ywfeUtils_esm = {};
8359
8359
 
8360
8360
  function request(_a) {
8361
8361
  return __awaiter(this, arguments, void 0, function (_b) {
8362
- var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, res;
8362
+ var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, response, message, result;
8363
8363
  var input = _b.input;
8364
8364
  return __generator(this, function (_c) {
8365
8365
  switch (_c.label) {
8366
8366
  case 0:
8367
- method = input.method || 'GET';
8367
+ method = input.method || "GET";
8368
8368
  basePathMap = new Map([
8369
- ['prod', 'https://gateway.ywwl.com'],
8370
- ['test', 'https://test-gateway.ywwl.com'],
8371
- ['test2', 'https://test2-gateway.ywwl.com'],
8372
- ['dev', 'https://dev-gateway.ywwl.com'],
8369
+ ["prod", "https://gateway.ywwl.com"],
8370
+ ["test", "https://test-gateway.ywwl.com"],
8371
+ ["test2", "https://test2-gateway.ywwl.com"],
8372
+ ["dev", "https://dev-gateway.ywwl.com"],
8373
8373
  ]);
8374
8374
  getBasePath = function () {
8375
- var env = 'test';
8375
+ var env = "test";
8376
8376
  return basePathMap.get(env);
8377
8377
  };
8378
8378
  isValidURL = function (url) {
8379
- var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
8380
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
8381
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
8382
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
8383
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
8384
- '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
8379
+ var pattern = new RegExp("^(https?:\\/\\/)?" + // protocol
8380
+ "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
8381
+ "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
8382
+ "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
8383
+ "(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
8384
+ "(\\#[-a-z\\d_]*)?$", "i"); // fragment locator
8385
8385
  return !!pattern.test(url);
8386
8386
  };
8387
8387
  prefix = getBasePath();
@@ -8389,20 +8389,27 @@ function request(_a) {
8389
8389
  fetchOption = {
8390
8390
  method: method,
8391
8391
  headers: {
8392
- 'Content-type': 'application/json',
8393
- 'x-token': 'a9c20b15cbc43b27b80e38b1626f54e3d9b6e8b7fc454c508f533f3bf0d960279be506171fd641ba43b229856bba348d',
8392
+ "Content-type": "application/json",
8393
+ "x-token": "a9c20b15cbc43b27b80e38b1626f54e3d9b6e8b7fc454c508f533f3bf0d960279be506171fd641ba43b229856bba348d",
8394
8394
  },
8395
8395
  };
8396
- if (method.toUpperCase() === 'POST') {
8396
+ if (method.toUpperCase() === "POST") {
8397
8397
  fetchOption.body = JSON.stringify(input.params);
8398
8398
  }
8399
- else if (method.toUpperCase() === 'GET') {
8399
+ else if (method.toUpperCase() === "GET") {
8400
8400
  requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
8401
8401
  }
8402
8402
  return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8403
8403
  case 1:
8404
- res = _c.sent();
8405
- return [2 /*return*/, res.json()];
8404
+ response = _c.sent();
8405
+ if (!response.ok) {
8406
+ message = "An error has occured: ".concat(response.status);
8407
+ return [2 /*return*/, { success: false, message: message }];
8408
+ }
8409
+ return [4 /*yield*/, response.json()];
8410
+ case 2:
8411
+ result = _c.sent();
8412
+ return [2 /*return*/, result];
8406
8413
  }
8407
8414
  });
8408
8415
  });