@brytdesigns/shopify-ajax-predictive-search-api 1.0.5 → 1.0.6

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
@@ -7009,6 +7009,7 @@ var logWithLevel = (level) => (...message) => {
7009
7009
  });
7010
7010
  };
7011
7011
  var logInfo = /* @__PURE__ */ logWithLevel(Info);
7012
+ var logError = /* @__PURE__ */ logWithLevel(Error2);
7012
7013
  var withLogSpan = /* @__PURE__ */ dual(2, (effect3, label) => flatMap7(currentTimeMillis2, (now) => fiberRefLocallyWith(effect3, currentLogSpan, prepend3(make26(label, now)))));
7013
7014
  var mapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, {
7014
7015
  onFailure: (c) => failCauseSync(() => f(c)),
@@ -11477,6 +11478,7 @@ var match12 = match8;
11477
11478
  var matchCause4 = matchCause;
11478
11479
  var matchCauseEffect3 = matchCauseEffect;
11479
11480
  var logInfo2 = logInfo;
11481
+ var logError2 = logError;
11480
11482
  var withLogSpan2 = withLogSpan;
11481
11483
  var annotateLogsScoped2 = annotateLogsScoped;
11482
11484
  var runtime3 = runtime2;
@@ -17972,6 +17974,50 @@ extend3(
17972
17974
  })
17973
17975
  );
17974
17976
  var Default = layer2;
17977
+ var formatCause = (cause2) => {
17978
+ if (cause2 == null) return void 0;
17979
+ if (cause2 instanceof Error) {
17980
+ const nested2 = formatCause(cause2.cause);
17981
+ const base = `${cause2.name}: ${cause2.message}`;
17982
+ return nested2 ? `${base} -> ${nested2}` : base;
17983
+ }
17984
+ if (typeof cause2 === "object") {
17985
+ try {
17986
+ return JSON.stringify(cause2);
17987
+ } catch {
17988
+ return String(cause2);
17989
+ }
17990
+ }
17991
+ return String(cause2);
17992
+ };
17993
+ var toError = (error) => {
17994
+ if (error._tag === "RequestError" || error._tag === "ResponseError") {
17995
+ const detail = formatCause(error.cause);
17996
+ const message2 = detail ? `${error.message}: ${detail}` : error.message;
17997
+ return Object.assign(new Error(message2, { cause: error.cause }), {
17998
+ _tag: error._tag,
17999
+ reason: error.reason
18000
+ });
18001
+ }
18002
+ if (error._tag === "ParseError" || error._tag === "@brytdesigns/ajax-client/InvalidAjaxMethodError") {
18003
+ return new Error(error.message, { cause: error.cause });
18004
+ }
18005
+ if (error._tag === "HttpBodyError") {
18006
+ const reason = error.reason;
18007
+ if (reason._tag === "JsonError") {
18008
+ return new Error("Failed to serialize JSON request body", {
18009
+ cause: reason
18010
+ });
18011
+ }
18012
+ if (reason._tag === "SchemaError") {
18013
+ return new Error(reason.error.message, {
18014
+ cause: reason.error.cause
18015
+ });
18016
+ }
18017
+ }
18018
+ const message = formatCause(error) ?? error?.message ?? error?.toString?.() ?? String(error);
18019
+ return new Error(message, { cause: error });
18020
+ };
17975
18021
  var METHOD = {
17976
18022
  GET: "get",
17977
18023
  POST: "post"
@@ -18069,29 +18115,13 @@ var makeFactory = ({
18069
18115
  withNamespacedLogSpan(
18070
18116
  routeName.replace("_url", "").replace("_", ":")
18071
18117
  ),
18072
- catchAll2((error) => {
18073
- if (error._tag === "ParseError" || error._tag === "RequestError" || error._tag === "ResponseError" || error._tag === "@brytdesigns/ajax-client/InvalidAjaxMethodError") {
18074
- return fail7(
18075
- new Error(error.message, {
18076
- cause: error.cause
18077
- })
18078
- );
18079
- }
18080
- if (error._tag === "HttpBodyError") {
18081
- const reason = error.reason;
18082
- if (reason._tag === "JsonError") {
18083
- return fail7(new Error("Failed to parse JSON response"));
18084
- }
18085
- if (reason._tag === "SchemaError") {
18086
- return fail7(
18087
- new Error(reason.error.message, {
18088
- cause: reason.error.cause
18089
- })
18090
- );
18091
- }
18092
- }
18093
- return fail7(new Error(error.toString()));
18094
- })
18118
+ // Log the full failure cause (including defects and the underlying
18119
+ // `cause` chain) before we flatten it. This is gated by the consumer's
18120
+ // minimum log level, so it only surfaces when `debug` is enabled.
18121
+ tapErrorCause2(
18122
+ (cause2) => logError2("Ajax request failed", cause2)
18123
+ ),
18124
+ catchAll2((error) => fail7(toError(error)))
18095
18125
  );
18096
18126
 
18097
18127
  // src/effect/schema.ts