Compare commits

...

2 commits

View file

@ -92,6 +92,17 @@ function toLatinDigits(str) {
});
}
function getApiErrorMessage(body, fallback) {
const detailsMessage = body?.details?.message;
if (typeof detailsMessage === "string" && detailsMessage.trim()) {
return detailsMessage.trim();
}
if (typeof body?.status_message === "string" && body.status_message.trim()) {
return body.status_message.trim();
}
return fallback;
}
// Normalizes Iranian mobile numbers (09xxxxxxxxx, 9xxxxxxxxx, 0098/98/+98 prefixed) to E.164.
function toE164(raw) {
let cleaned = toLatinDigits(raw.trim()).replace(/[\s-]/g, "");
@ -111,6 +122,7 @@ async function submitInviteRequest(inviteCode, mobileNumber, token) {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
"Accept-Language": "fa",
},
body: JSON.stringify({
invite_code: inviteCode,
@ -125,7 +137,9 @@ async function submitInviteRequest(inviteCode, mobileNumber, token) {
} catch (_) {
// no JSON body
}
const error = new Error(body?.status_message || `Invite request failed (${response.status})`);
const error = new Error(
getApiErrorMessage(body, `Invite request failed (${response.status})`)
);
error.status = response.status;
error.body = body;
throw error;