Harden wallet challenge proxy

This commit is contained in:
2569718930@qq.com
2026-06-01 22:15:38 +08:00
parent 8fc9f3ae1a
commit fc0a8b8ff5
4 changed files with 127 additions and 21 deletions
@@ -68,6 +68,29 @@ export type NormalizedPaymentError = {
userRejected: boolean;
};
export async function readPaymentApiErrorMessage(
response: Response,
fallback = "Request failed",
limit = 300,
) {
const raw = (await response.text()).slice(0, limit);
if (!raw) return fallback;
try {
const parsed = JSON.parse(raw) as {
error?: unknown;
detail?: unknown;
message?: unknown;
};
const message = [parsed.error, parsed.detail, parsed.message].find(
(item) => typeof item === "string" && item.trim(),
);
if (typeof message === "string") return message.trim();
} catch {
// Fall back to the raw response body below.
}
return raw;
}
export function normalizePaymentError(error: unknown): NormalizedPaymentError {
const source = error as any;
const code = Number(