@brytdesigns/shopify-ajax-client 1.0.7 → 1.0.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.
package/dist/esm/index.js CHANGED
@@ -6994,6 +6994,7 @@ var logWithLevel = (level) => (...message) => {
6994
6994
  });
6995
6995
  };
6996
6996
  var logInfo = /* @__PURE__ */ logWithLevel(Info);
6997
+ var logError = /* @__PURE__ */ logWithLevel(Error2);
6997
6998
  var withLogSpan = /* @__PURE__ */ dual(2, (effect3, label) => flatMap7(currentTimeMillis2, (now) => fiberRefLocallyWith(effect3, currentLogSpan, prepend3(make26(label, now)))));
6998
6999
  var mapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, {
6999
7000
  onFailure: (c) => failCauseSync(() => f(c)),
@@ -11229,6 +11230,7 @@ var match11 = match8;
11229
11230
  var matchCause3 = matchCause;
11230
11231
  var matchCauseEffect3 = matchCauseEffect;
11231
11232
  var logInfo2 = logInfo;
11233
+ var logError2 = logError;
11232
11234
  var withLogSpan2 = withLogSpan;
11233
11235
  var annotateLogsScoped2 = annotateLogsScoped;
11234
11236
  var runtime3 = runtime2;
@@ -17512,6 +17514,50 @@ extend3(
17512
17514
  })
17513
17515
  );
17514
17516
  var Default = layer2;
17517
+ var formatCause = (cause2) => {
17518
+ if (cause2 == null) return void 0;
17519
+ if (cause2 instanceof Error) {
17520
+ const nested2 = formatCause(cause2.cause);
17521
+ const base = `${cause2.name}: ${cause2.message}`;
17522
+ return nested2 ? `${base} -> ${nested2}` : base;
17523
+ }
17524
+ if (typeof cause2 === "object") {
17525
+ try {
17526
+ return JSON.stringify(cause2);
17527
+ } catch {
17528
+ return String(cause2);
17529
+ }
17530
+ }
17531
+ return String(cause2);
17532
+ };
17533
+ var toError = (error) => {
17534
+ if (error._tag === "RequestError" || error._tag === "ResponseError") {
17535
+ const detail = formatCause(error.cause);
17536
+ const message2 = detail ? `${error.message}: ${detail}` : error.message;
17537
+ return Object.assign(new Error(message2, { cause: error.cause }), {
17538
+ _tag: error._tag,
17539
+ reason: error.reason
17540
+ });
17541
+ }
17542
+ if (error._tag === "ParseError" || error._tag === "@brytdesigns/ajax-client/InvalidAjaxMethodError") {
17543
+ return new Error(error.message, { cause: error.cause });
17544
+ }
17545
+ if (error._tag === "HttpBodyError") {
17546
+ const reason = error.reason;
17547
+ if (reason._tag === "JsonError") {
17548
+ return new Error("Failed to serialize JSON request body", {
17549
+ cause: reason
17550
+ });
17551
+ }
17552
+ if (reason._tag === "SchemaError") {
17553
+ return new Error(reason.error.message, {
17554
+ cause: reason.error.cause
17555
+ });
17556
+ }
17557
+ }
17558
+ const message = formatCause(error) ?? error?.message ?? error?.toString?.() ?? String(error);
17559
+ return new Error(message, { cause: error });
17560
+ };
17515
17561
  var METHOD = {
17516
17562
  GET: "get",
17517
17563
  POST: "post"
@@ -17622,29 +17668,13 @@ var makeFactory = ({
17622
17668
  withNamespacedLogSpan(
17623
17669
  routeName.replace("_url", "").replace("_", ":")
17624
17670
  ),
17625
- catchAll2((error) => {
17626
- if (error._tag === "ParseError" || error._tag === "RequestError" || error._tag === "ResponseError" || error._tag === "@brytdesigns/ajax-client/InvalidAjaxMethodError") {
17627
- return fail6(
17628
- new Error(error.message, {
17629
- cause: error.cause
17630
- })
17631
- );
17632
- }
17633
- if (error._tag === "HttpBodyError") {
17634
- const reason = error.reason;
17635
- if (reason._tag === "JsonError") {
17636
- return fail6(new Error("Failed to parse JSON response"));
17637
- }
17638
- if (reason._tag === "SchemaError") {
17639
- return fail6(
17640
- new Error(reason.error.message, {
17641
- cause: reason.error.cause
17642
- })
17643
- );
17644
- }
17645
- }
17646
- return fail6(new Error(error.toString()));
17647
- })
17671
+ // Log the full failure cause (including defects and the underlying
17672
+ // `cause` chain) before we flatten it. This is gated by the consumer's
17673
+ // minimum log level, so it only surfaces when `debug` is enabled.
17674
+ tapErrorCause2(
17675
+ (cause2) => logError2("Ajax request failed", cause2)
17676
+ ),
17677
+ catchAll2((error) => fail6(toError(error)))
17648
17678
  );
17649
17679
 
17650
17680
  export { Default, makeFactory };