owostack 0.3.0 → 0.3.1
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/index.js +56 -12
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -816,12 +816,8 @@ var Owostack = class {
|
|
|
816
816
|
body: JSON.stringify(body)
|
|
817
817
|
});
|
|
818
818
|
if (!response.ok) {
|
|
819
|
-
const
|
|
820
|
-
|
|
821
|
-
throw new OwostackError(
|
|
822
|
-
errorData.code || "unknown_error",
|
|
823
|
-
errorData.message || errorData.error || "Request failed"
|
|
824
|
-
);
|
|
819
|
+
const errorData = extractErrorDetails(await readErrorResponse(response));
|
|
820
|
+
throw new OwostackError(errorData.code, errorData.message);
|
|
825
821
|
}
|
|
826
822
|
return response.json();
|
|
827
823
|
}
|
|
@@ -844,16 +840,64 @@ var Owostack = class {
|
|
|
844
840
|
}
|
|
845
841
|
});
|
|
846
842
|
if (!response.ok) {
|
|
847
|
-
const
|
|
848
|
-
|
|
849
|
-
throw new OwostackError(
|
|
850
|
-
errorData.code || "unknown_error",
|
|
851
|
-
errorData.message || errorData.error || "Request failed"
|
|
852
|
-
);
|
|
843
|
+
const errorData = extractErrorDetails(await readErrorResponse(response));
|
|
844
|
+
throw new OwostackError(errorData.code, errorData.message);
|
|
853
845
|
}
|
|
854
846
|
return response.json();
|
|
855
847
|
}
|
|
856
848
|
};
|
|
849
|
+
function isRecord(value) {
|
|
850
|
+
return typeof value === "object" && value !== null;
|
|
851
|
+
}
|
|
852
|
+
function asNonEmptyString(value) {
|
|
853
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
854
|
+
}
|
|
855
|
+
async function readErrorResponse(response) {
|
|
856
|
+
const raw = await response.text().catch(() => "");
|
|
857
|
+
if (!raw) return null;
|
|
858
|
+
try {
|
|
859
|
+
return JSON.parse(raw);
|
|
860
|
+
} catch {
|
|
861
|
+
return raw;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
function extractErrorDetails(payload) {
|
|
865
|
+
if (typeof payload === "string") {
|
|
866
|
+
return {
|
|
867
|
+
code: "unknown_error",
|
|
868
|
+
message: payload
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
if (!isRecord(payload)) {
|
|
872
|
+
return {
|
|
873
|
+
code: "unknown_error",
|
|
874
|
+
message: "Request failed"
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
const directCode = asNonEmptyString(payload.code);
|
|
878
|
+
const directMessage = asNonEmptyString(payload.message);
|
|
879
|
+
const directError = payload.error;
|
|
880
|
+
if (typeof directError === "string") {
|
|
881
|
+
return {
|
|
882
|
+
code: directCode || "unknown_error",
|
|
883
|
+
message: directError
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
if (isRecord(directError)) {
|
|
887
|
+
const nestedCode = asNonEmptyString(directError.code);
|
|
888
|
+
const nestedMessage = asNonEmptyString(directError.message) || asNonEmptyString(directError.error);
|
|
889
|
+
if (nestedMessage) {
|
|
890
|
+
return {
|
|
891
|
+
code: nestedCode || directCode || "unknown_error",
|
|
892
|
+
message: nestedMessage
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return {
|
|
897
|
+
code: directCode || "unknown_error",
|
|
898
|
+
message: directMessage || "Request failed"
|
|
899
|
+
};
|
|
900
|
+
}
|
|
857
901
|
function buildPlansFn(client) {
|
|
858
902
|
const fn = ((params) => {
|
|
859
903
|
const query = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owostack",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Core SDK for Owostack billing infrastructure",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"payments"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@owostack/types": "0.3.
|
|
33
|
+
"@owostack/types": "0.3.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"tsup": "^8.3.6",
|