@crmcom/self-service-sdk 3.0.0-build.7 → 3.0.0-build.8

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.
Files changed (2) hide show
  1. package/httpUtil.js +32 -10
  2. package/package.json +1 -1
package/httpUtil.js CHANGED
@@ -481,16 +481,38 @@ async function get({
481
481
  return { code: response.status, bodyText: bodyText, error: json2Obj(bodyText) };
482
482
  }
483
483
  } catch (e) {
484
- logger.error("Request error:", e);
485
- let bodyText = await e.text();
486
- // if (e.status == '401') {
487
- // let uri = getURI(isBackend, resourcePath);
488
- // if (queryParams)
489
- // uri = uri + '?' + querystring.encode(cleanObj(queryParams));
490
- // var result = await processRefreshToken(uri,logOutIfSessionInvalid,returnText);
491
- // return result;
492
- // }
493
- return { code: e.status, bodyText: bodyText, error: json2Obj(bodyText) };
484
+ logger.error("Request error:", e);
485
+
486
+ // If fetch throws (CORS/network), e is usually a TypeError with message "Failed to fetch"
487
+ const message = e?.message || String(e);
488
+
489
+ // Some codebases throw a Response object; handle that too (rare, but possible)
490
+ const isResponseLike = e && typeof e.text === "function" && typeof e.status !== "undefined";
491
+
492
+ if (isResponseLike) {
493
+ let bodyText = "";
494
+ try {
495
+ bodyText = await e.text();
496
+ } catch (_) {}
497
+ return { code: String(e.status || "UNKNOWN"), bodyText, error: bodyText ? json2Obj(bodyText) : null };
498
+ }
499
+
500
+ // No response exists => network/CORS/etc.
501
+ return {
502
+ code: "NETWORK_ERROR",
503
+ bodyText: message,
504
+ error: { message }
505
+ };
506
+ // logger.error("Request error:", e);
507
+ // let bodyText = await e.text();
508
+ // // if (e.status == '401') {
509
+ // // let uri = getURI(isBackend, resourcePath);
510
+ // // if (queryParams)
511
+ // // uri = uri + '?' + querystring.encode(cleanObj(queryParams));
512
+ // // var result = await processRefreshToken(uri,logOutIfSessionInvalid,returnText);
513
+ // // return result;
514
+ // // }
515
+ // return { code: e.status, bodyText: bodyText, error: json2Obj(bodyText) };
494
516
  }
495
517
  }
496
518
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crmcom/self-service-sdk",
3
- "version": "3.0.0-build.7",
3
+ "version": "3.0.0-build.8",
4
4
  "description": "Official CRM.COM Self-Service JavaScript SDK for consumer-facing API integration",
5
5
  "type": "module",
6
6
  "main": "index.js",