diff --git a/js/script.js b/js/script.js index 8dc3d31..4b1d1e7 100644 --- a/js/script.js +++ b/js/script.js @@ -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. function toE164(raw) { let cleaned = toLatinDigits(raw.trim()).replace(/[\s-]/g, ""); @@ -98,6 +109,7 @@ async function submitInviteRequest(inviteCode, mobileNumber, token) { headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, + "Accept-Language": "fa", }, body: JSON.stringify({ invite_code: inviteCode, @@ -112,7 +124,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;