fix(sms): accept a gateway reply with debug text before its JSON

The relay gateway now prints timing lines before its result, e.g.
"1. Function Start at: ...<br>...572381951{"data":"sent"}". The message
was delivered, but the whole body is not JSON, so it was logged as a failed
SMS. When the body does not parse, the trailing JSON object is read instead.
A body with no JSON at all (the gateway's bare PHP errors) still fails.

Tests: sms.service.spec (relayRejection). 33 SMS tests pass.

پیامکِ ارسال‌شده دیگر به اشتباه در گزارش سرور «ناموفق» ثبت نمی‌شود.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
s.esmaeili
2026-10-10 16:39:41 +03:30
co-authored by Cursor
parent 797d030e67
commit 840311a2a0
3 changed files with 28 additions and 3 deletions
+8 -1
View File
@@ -87622,7 +87622,14 @@ var require_relay_driver = __commonJS({
try {
data = JSON.parse(text);
} catch {
return text.slice(0, 200);
const trailing = /\{[^{}]*\}$/.exec(text);
try {
if (!trailing)
throw new Error("no json");
data = JSON.parse(trailing[0]);
} catch {
return text.slice(0, 200);
}
}
if (!data || typeof data !== "object" || Array.isArray(data))
return null;