@rhea-finance/confidential-swap 0.2.7 → 0.2.8
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.cjs +19 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -604,6 +604,18 @@ function record(value) {
|
|
|
604
604
|
responseAssert(value && typeof value === "object" && !Array.isArray(value), "Expected an object response.");
|
|
605
605
|
return value;
|
|
606
606
|
}
|
|
607
|
+
function httpErrorMessage(data, status, content) {
|
|
608
|
+
if (data && typeof data === "object" && !Array.isArray(data)) {
|
|
609
|
+
const body = data;
|
|
610
|
+
const apiMessage = [body.message, body.error, body.msg].find(
|
|
611
|
+
(value) => typeof value === "string" && value.trim()
|
|
612
|
+
);
|
|
613
|
+
if (typeof apiMessage === "string") return apiMessage.trim();
|
|
614
|
+
}
|
|
615
|
+
const trimmed = content.trim();
|
|
616
|
+
if (trimmed && !trimmed.startsWith("<") && trimmed.length <= 300) return trimmed;
|
|
617
|
+
return `Service request failed (${status}).`;
|
|
618
|
+
}
|
|
607
619
|
var HttpConfidentialApi = class {
|
|
608
620
|
constructor(config) {
|
|
609
621
|
this.config = config;
|
|
@@ -652,7 +664,13 @@ var HttpConfidentialApi = class {
|
|
|
652
664
|
} catch {
|
|
653
665
|
throw new ConfidentialSwapError("INVALID_RESPONSE", "Service returned invalid JSON.", response.status);
|
|
654
666
|
}
|
|
655
|
-
if (!response.ok)
|
|
667
|
+
if (!response.ok) {
|
|
668
|
+
throw new ConfidentialSwapError(
|
|
669
|
+
response.status === 401 || response.status === 403 ? "UNAUTHORIZED" : "HTTP_ERROR",
|
|
670
|
+
httpErrorMessage(data, response.status, content),
|
|
671
|
+
response.status
|
|
672
|
+
);
|
|
673
|
+
}
|
|
656
674
|
return data;
|
|
657
675
|
} catch (error) {
|
|
658
676
|
throwIfAborted(signal);
|