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