@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.
- package/dist/adapters/index.js +24 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +24 -1
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.js +24 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -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 {
|
|
@@ -3721,9 +3726,11 @@ var BaseCustomService = class {
|
|
|
3721
3726
|
statusText: response.statusText,
|
|
3722
3727
|
duration
|
|
3723
3728
|
});
|
|
3724
|
-
|
|
3729
|
+
const error = new Error(
|
|
3725
3730
|
`Request failed: ${response.status} ${response.statusText}`
|
|
3726
3731
|
);
|
|
3732
|
+
error.status = response.status;
|
|
3733
|
+
throw error;
|
|
3727
3734
|
}
|
|
3728
3735
|
this.logger.info("API request successful", {
|
|
3729
3736
|
method,
|
|
@@ -3899,6 +3906,14 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
3899
3906
|
});
|
|
3900
3907
|
} catch (error) {
|
|
3901
3908
|
this.logger.error("Error in getProduct", void 0, { error });
|
|
3909
|
+
if (!isUpstreamUnavailable(error)) {
|
|
3910
|
+
return formatResponse({
|
|
3911
|
+
success: true,
|
|
3912
|
+
message: "Request completed successfully. No product found.",
|
|
3913
|
+
data: null,
|
|
3914
|
+
meta: void 0
|
|
3915
|
+
});
|
|
3916
|
+
}
|
|
3902
3917
|
const safeMessage = error instanceof Error ? error.message : "An unexpected error occurred while processing the request.";
|
|
3903
3918
|
return formatResponse({
|
|
3904
3919
|
success: false,
|
|
@@ -4112,6 +4127,14 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4112
4127
|
});
|
|
4113
4128
|
} catch (error) {
|
|
4114
4129
|
this.logger.error("Error in getCollection", void 0, { error });
|
|
4130
|
+
if (!isUpstreamUnavailable(error)) {
|
|
4131
|
+
return formatResponse({
|
|
4132
|
+
success: true,
|
|
4133
|
+
message: "Request completed successfully. No collection found.",
|
|
4134
|
+
data: null,
|
|
4135
|
+
meta: void 0
|
|
4136
|
+
});
|
|
4137
|
+
}
|
|
4115
4138
|
const safeMessage = error instanceof Error ? error.message : "An unexpected error occurred while processing the request.";
|
|
4116
4139
|
return formatResponse({
|
|
4117
4140
|
success: false,
|