FIX(invite): correct error message

correct error message
This commit is contained in:
Haydar Ghasemi 2026-08-23 12:59:55 +03:30
parent 0d09ee74c3
commit 8cff71098c

View file

@ -79,6 +79,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. // Normalizes Iranian mobile numbers (09xxxxxxxxx, 9xxxxxxxxx, 0098/98/+98 prefixed) to E.164.
function toE164(raw) { function toE164(raw) {
let cleaned = toLatinDigits(raw.trim()).replace(/[\s-]/g, ""); let cleaned = toLatinDigits(raw.trim()).replace(/[\s-]/g, "");
@ -98,6 +109,7 @@ async function submitInviteRequest(inviteCode, mobileNumber, token) {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
"Accept-Language": "fa",
}, },
body: JSON.stringify({ body: JSON.stringify({
invite_code: inviteCode, invite_code: inviteCode,
@ -112,7 +124,9 @@ async function submitInviteRequest(inviteCode, mobileNumber, token) {
} catch (_) { } catch (_) {
// no JSON body // 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.status = response.status;
error.body = body; error.body = body;
throw error; throw error;