@shopkit/data-layer 1.4.2 → 1.4.3

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.
@@ -159,6 +159,11 @@ function createDomainLogger(domain, adapter, config = {}) {
159
159
  }
160
160
 
161
161
  // src/core/utils.ts
162
+ function isUpstreamUnavailable(error) {
163
+ const status = error?.status;
164
+ if (typeof status !== "number") return true;
165
+ return status >= 500;
166
+ }
162
167
  function formatResponse(params) {
163
168
  const { success, message, data = null, error = null, meta = {} } = params;
164
169
  return {
@@ -3728,9 +3733,11 @@ var BaseCustomService = class {
3728
3733
  statusText: response.statusText,
3729
3734
  duration
3730
3735
  });
3731
- throw new Error(
3736
+ const error = new Error(
3732
3737
  `Request failed: ${response.status} ${response.statusText}`
3733
3738
  );
3739
+ error.status = response.status;
3740
+ throw error;
3734
3741
  }
3735
3742
  this.logger.info("API request successful", {
3736
3743
  method,
@@ -3906,6 +3913,14 @@ var ProductService2 = class extends BaseCustomService {
3906
3913
  });
3907
3914
  } catch (error) {
3908
3915
  this.logger.error("Error in getProduct", void 0, { error });
3916
+ if (!isUpstreamUnavailable(error)) {
3917
+ return formatResponse({
3918
+ success: true,
3919
+ message: "Request completed successfully. No product found.",
3920
+ data: null,
3921
+ meta: void 0
3922
+ });
3923
+ }
3909
3924
  const safeMessage = error instanceof Error ? error.message : "An unexpected error occurred while processing the request.";
3910
3925
  return formatResponse({
3911
3926
  success: false,
@@ -4119,6 +4134,14 @@ var ProductService2 = class extends BaseCustomService {
4119
4134
  });
4120
4135
  } catch (error) {
4121
4136
  this.logger.error("Error in getCollection", void 0, { error });
4137
+ if (!isUpstreamUnavailable(error)) {
4138
+ return formatResponse({
4139
+ success: true,
4140
+ message: "Request completed successfully. No collection found.",
4141
+ data: null,
4142
+ meta: void 0
4143
+ });
4144
+ }
4122
4145
  const safeMessage = error instanceof Error ? error.message : "An unexpected error occurred while processing the request.";
4123
4146
  return formatResponse({
4124
4147
  success: false,