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