Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): stop bulk checks that cannot succeed

Yudhi Armyndhariscb24ff564599
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index ed4b98cfb..c71e7d26e 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -1127,6 +1127,7 @@
"partial_few": "{{reason}} (HTTP {{status}}). توقف الفحص عند الرقم {{attempted}} من أصل {{total}}؛ لم يُرسَل {{count}} أرقام. حاول مرة أخرى لاحقًا.",
"partial_many": "{{reason}} (HTTP {{status}}). توقف الفحص عند الرقم {{attempted}} من أصل {{total}}؛ لم يُرسَل {{count}} رقمًا. حاول مرة أخرى لاحقًا.",
"partial_zero": "{{reason}} (HTTP {{status}}). توقف الفحص عند الرقم {{attempted}} من أصل {{total}}؛ لم يُرسَل {{count}} رقم. حاول مرة أخرى لاحقًا.",
+ "noAnswer": "لم تردّ البوابة. توقف الفحص عند الرقم {{attempted}} من أصل {{total}}. حاول مرة أخرى لاحقًا.",
"last": "{{reason}} (HTTP {{status}}). فشل آخر استعلام. حاول مرة أخرى لاحقًا."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index d37111f23..816ffb626 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -1094,6 +1094,7 @@
"reasonOther": "Das Gateway hat eine Abfrage abgelehnt",
"partial": "{{reason}} (HTTP {{status}}). Gestoppt bei Nummer {{attempted}} von {{total}}; {{count}} Nummer wurde nicht geprüft. Versuche es später erneut.",
"partial_other": "{{reason}} (HTTP {{status}}). Gestoppt bei Nummer {{attempted}} von {{total}}; {{count}} Nummern wurden nicht geprüft. Versuche es später erneut.",
+ "noAnswer": "Das Gateway hat nicht geantwortet. Gestoppt bei Nummer {{attempted}} von {{total}}. Versuche es später erneut.",
"last": "{{reason}} (HTTP {{status}}). Die letzte Abfrage ist fehlgeschlagen. Versuche es später erneut."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index fcad21321..789b64949 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -1094,6 +1094,7 @@
"reasonOther": "The gateway refused a lookup",
"partial": "{{reason}} (HTTP {{status}}). Stopped at number {{attempted}} of {{total}}; {{count}} number was not sent. Try again later.",
"partial_other": "{{reason}} (HTTP {{status}}). Stopped at number {{attempted}} of {{total}}; {{count}} numbers were not sent. Try again later.",
+ "noAnswer": "The gateway did not answer. Stopped at number {{attempted}} of {{total}}. Try again later.",
"last": "{{reason}} (HTTP {{status}}). The last lookup failed. Try again later."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index a8fb63789..f7e4c1832 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -1102,6 +1102,7 @@
"partial": "{{reason}} (HTTP {{status}}). La verificación se detuvo en el número {{attempted}} de {{total}}; {{count}} número no se envió. Inténtalo de nuevo más tarde.",
"partial_other": "{{reason}} (HTTP {{status}}). La verificación se detuvo en el número {{attempted}} de {{total}}; {{count}} números no se enviaron. Inténtalo de nuevo más tarde.",
"partial_many": "{{reason}} (HTTP {{status}}). La verificación se detuvo en el número {{attempted}} de {{total}}; {{count}} números no se enviaron. Inténtalo de nuevo más tarde.",
+ "noAnswer": "La puerta de enlace no respondió. La verificación se detuvo en el número {{attempted}} de {{total}}. Inténtalo de nuevo más tarde.",
"last": "{{reason}} (HTTP {{status}}). Falló la última consulta. Inténtalo de nuevo más tarde."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index 6bf877b33..466e47177 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -1102,6 +1102,7 @@
"partial": "{{reason}} (HTTP {{status}}). Arrêt au numéro {{attempted}} sur {{total}} ; {{count}} numéro n'a pas été vérifié. Réessayez plus tard.",
"partial_other": "{{reason}} (HTTP {{status}}). Arrêt au numéro {{attempted}} sur {{total}} ; {{count}} numéros n'ont pas été vérifiés. Réessayez plus tard.",
"partial_many": "{{reason}} (HTTP {{status}}). Arrêt au numéro {{attempted}} sur {{total}} ; {{count}} numéros n'ont pas été vérifiés. Réessayez plus tard.",
+ "noAnswer": "La passerelle n'a pas répondu. Arrêt au numéro {{attempted}} sur {{total}}. Réessayez plus tard.",
"last": "{{reason}} (HTTP {{status}}). La dernière requête a échoué. Réessayez plus tard."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 81ed024eb..80552adcb 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -1111,6 +1111,7 @@
"partial_many": "{{reason}} (HTTP {{status}}). הבדיקה נעצרה במספר {{attempted}} מתוך {{total}}; {{count}} מספרים לא נשלחו. יש לנסות שוב מאוחר יותר.",
"partial_other": "{{reason}} (HTTP {{status}}). הבדיקה נעצרה במספר {{attempted}} מתוך {{total}}; {{count}} מספרים לא נשלחו. יש לנסות שוב מאוחר יותר.",
"partial_two": "{{reason}} (HTTP {{status}}). הבדיקה נעצרה במספר {{attempted}} מתוך {{total}}; שני מספרים לא נשלחו. יש לנסות שוב מאוחר יותר.",
+ "noAnswer": "השער לא השיב. הבדיקה נעצרה במספר {{attempted}} מתוך {{total}}. יש לנסות שוב מאוחר יותר.",
"last": "{{reason}} (HTTP {{status}}). השאילתה האחרונה נכשלה. יש לנסות שוב מאוחר יותר."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.json
index f6ea1766d..5233683e9 100644
--- a/dashboard/src/i18n/locales/hi.json
+++ b/dashboard/src/i18n/locales/hi.json
@@ -1094,6 +1094,7 @@
"reasonOther": "गेटवे ने एक जाँच अस्वीकार कर दी",
"partial": "{{reason}} (HTTP {{status}})। {{total}} में से {{attempted}} नंबर जाँच के लिए भेजे जाने के बाद बैच रुक गया; {{count}} नंबर नहीं भेजा गया। बाद में पुनः प्रयास करें।",
"partial_other": "{{reason}} (HTTP {{status}})। {{total}} में से {{attempted}} नंबर जाँच के लिए भेजे जाने के बाद बैच रुक गया; {{count}} नंबर नहीं भेजे गए। बाद में पुनः प्रयास करें।",
+ "noAnswer": "गेटवे ने जवाब नहीं दिया। {{total}} में से {{attempted}} नंबर जाँच के लिए भेजे जाने के बाद बैच रुक गया। बाद में पुनः प्रयास करें।",
"last": "{{reason}} (HTTP {{status}})। अंतिम जाँच विफल रही। बाद में पुनः प्रयास करें।"
},
"toast": {
diff --git a/dashboard/src/i18n/locales/id.json b/dashboard/src/i18n/locales/id.json
index 878960ace..d844c657d 100644
--- a/dashboard/src/i18n/locales/id.json
+++ b/dashboard/src/i18n/locales/id.json
@@ -1094,6 +1094,7 @@
"reasonOther": "Gateway menolak pemeriksaan",
"partial": "{{reason}} (HTTP {{status}}). Berhenti di nomor {{attempted}} dari {{total}}; {{count}} nomor belum diperiksa. Coba lagi nanti.",
"partial_other": "{{reason}} (HTTP {{status}}). Berhenti di nomor {{attempted}} dari {{total}}; {{count}} nomor belum diperiksa. Coba lagi nanti.",
+ "noAnswer": "Gateway tidak merespons. Berhenti di nomor {{attempted}} dari {{total}}. Coba lagi nanti.",
"last": "{{reason}} (HTTP {{status}}). Pemeriksaan terakhir gagal. Coba lagi nanti."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index f2a9d5b01..1e30e3c91 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -1102,6 +1102,7 @@
"partial": "{{reason}} (HTTP {{status}}). Verifica interrotta al numero {{attempted}} di {{total}}; {{count}} numero non è stato inviato. Riprova più tardi.",
"partial_other": "{{reason}} (HTTP {{status}}). Verifica interrotta al numero {{attempted}} di {{total}}; {{count}} numeri non sono stati inviati. Riprova più tardi.",
"partial_many": "{{reason}} (HTTP {{status}}). Verifica interrotta al numero {{attempted}} di {{total}}; {{count}} numeri non sono stati inviati. Riprova più tardi.",
+ "noAnswer": "Il gateway non ha risposto. Verifica interrotta al numero {{attempted}} di {{total}}. Riprova più tardi.",
"last": "{{reason}} (HTTP {{status}}). L'ultima verifica non è riuscita. Riprova più tardi."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index ebc17bbff..a9eba6d96 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -1094,6 +1094,7 @@
"reasonOther": "게이트웨이가 조회를 거부했습니다",
"partial": "{{reason}} (HTTP {{status}}). {{total}}개 중 {{attempted}}번째 번호에서 중지되었으며, 나머지 {{count}}개는 확인하지 못했습니다. 나중에 다시 시도하세요.",
"partial_other": "{{reason}} (HTTP {{status}}). {{total}}개 중 {{attempted}}번째 번호에서 중지되었으며, 나머지 {{count}}개는 확인하지 못했습니다. 나중에 다시 시도하세요.",
+ "noAnswer": "게이트웨이가 응답하지 않았습니다. {{total}}개 중 {{attempted}}번째 번호에서 중지되었습니다. 나중에 다시 시도하세요.",
"last": "{{reason}} (HTTP {{status}}). 마지막 조회에 실패했습니다. 나중에 다시 시도하세요."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index ef2f1b30c..cb60ef793 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -1102,6 +1102,7 @@
"partial": "{{reason}} (HTTP {{status}}). A verificação parou no número {{attempted}} de {{total}}; {{count}} número não foi enviado. Tente novamente mais tarde.",
"partial_other": "{{reason}} (HTTP {{status}}). A verificação parou no número {{attempted}} de {{total}}; {{count}} números não foram enviados. Tente novamente mais tarde.",
"partial_many": "{{reason}} (HTTP {{status}}). A verificação parou no número {{attempted}} de {{total}}; {{count}} números não foram enviados. Tente novamente mais tarde.",
+ "noAnswer": "O gateway não respondeu. A verificação parou no número {{attempted}} de {{total}}. Tente novamente mais tarde.",
"last": "{{reason}} (HTTP {{status}}). A última consulta falhou. Tente novamente mais tarde."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index 143ee65c3..aea8d7735 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -1094,6 +1094,7 @@
"reasonOther": "గేట్‌వే ఒక తనిఖీని తిరస్కరించింది",
"partial": "{{reason}} (HTTP {{status}}). బ్యాచ్ {{total}}లో {{attempted}}వ నంబర్ వద్ద ఆగింది; {{count}} నంబర్ తనిఖీకి పంపబడలేదు. తర్వాత మళ్లీ ప్రయత్నించండి.",
"partial_other": "{{reason}} (HTTP {{status}}). బ్యాచ్ {{total}}లో {{attempted}}వ నంబర్ వద్ద ఆగింది; {{count}} నంబర్లు తనిఖీకి పంపబడలేదు. తర్వాత మళ్లీ ప్రయత్నించండి.",
+ "noAnswer": "గేట్‌వే స్పందించలేదు. బ్యాచ్ {{total}}లో {{attempted}}వ నంబర్ వద్ద ఆగింది. తర్వాత మళ్లీ ప్రయత్నించండి.",
"last": "{{reason}} (HTTP {{status}}). చివరి తనిఖీ విఫలమైంది. తర్వాత మళ్లీ ప్రయత్నించండి."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index be46aadc6..00b8f6c4a 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -1094,6 +1094,7 @@
"reasonOther": "Ağ geçidi bir sorguyu reddetti",
"partial": "{{reason}} (HTTP {{status}}). {{total}} numaradan {{attempted}}. numarada durduruldu; {{count}} numara gönderilmedi. Daha sonra tekrar deneyin.",
"partial_other": "{{reason}} (HTTP {{status}}). {{total}} numaradan {{attempted}}. numarada durduruldu; {{count}} numara gönderilmedi. Daha sonra tekrar deneyin.",
+ "noAnswer": "Ağ geçidi yanıt vermedi. {{total}} numaradan {{attempted}}. numarada durduruldu. Daha sonra tekrar deneyin.",
"last": "{{reason}} (HTTP {{status}}). Son sorgu başarısız oldu. Daha sonra tekrar deneyin."
},
"toast": {
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index 8cf12834e..3ddbbe645 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -1094,6 +1094,7 @@
"reasonOther": "网关拒绝了一次查询",
"partial": "{{reason}}(HTTP {{status}})。已在第 {{attempted}} 个号码处停止(共 {{total}} 个),其余 {{count}} 个号码未查询。请稍后重试。",
"partial_other": "{{reason}}(HTTP {{status}})。已在第 {{attempted}} 个号码处停止(共 {{total}} 个),其余 {{count}} 个号码未查询。请稍后重试。",
+ "noAnswer": "网关未响应。已在第 {{attempted}} 个号码处停止(共 {{total}} 个)。请稍后重试。",
"last": "{{reason}}(HTTP {{status}})。最后一次查询失败。请稍后重试。"
},
"toast": {
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index b97280687..af62de410 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -1094,6 +1094,7 @@
"reasonOther": "閘道拒絕了一次查詢",
"partial": "{{reason}}(HTTP {{status}})。已在第 {{attempted}} 個號碼處停止(共 {{total}} 個),其餘 {{count}} 個號碼未查詢。請稍後再試。",
"partial_other": "{{reason}}(HTTP {{status}})。已在第 {{attempted}} 個號碼處停止(共 {{total}} 個),其餘 {{count}} 個號碼未查詢。請稍後再試。",
+ "noAnswer": "閘道沒有回應。已在第 {{attempted}} 個號碼處停止(共 {{total}} 個)。請稍後再試。",
"last": "{{reason}}(HTTP {{status}})。最後一次查詢失敗。請稍後再試。"
},
"toast": {
diff --git a/dashboard/src/pages/NumberChecker.test.ts b/dashboard/src/pages/NumberChecker.test.ts
index ade1b05ca..95e17e6b2 100644
--- a/dashboard/src/pages/NumberChecker.test.ts
+++ b/dashboard/src/pages/NumberChecker.test.ts
@@ -496,12 +496,13 @@ test('NumberChecker: a gateway refusal stops the batch and the numbers never rea
});
const STOP_REASON: Record<number, RegExp> = {
+ 400: /The session is not connected \(HTTP 400\)/,
409: /The session is not connected \(HTTP 409\)/,
429: /The gateway rate limit was reached \(HTTP 429\)/,
503: /WhatsApp did not answer a lookup \(HTTP 503\)/,
};
-for (const status of [409, 429, 503]) {
+for (const status of [400, 409, 429, 503]) {
test(`NumberChecker: HTTP ${status} on the first lookup stops the batch before the second`, async () => {
const lookups = stubLookups(() => jsonResponse({ message: `refused ${status}` }, status));
const { container } = renderComponent();
@@ -519,6 +520,28 @@ for (const status of [409, 429, 503]) {
});
}
+test('NumberChecker: a lookup that gets no answer at all stops the batch before the second', async () => {
+ const lookups: string[] = [];
+ globalThis.fetch = ((input: RequestInfo | URL) => {
+ const url = String(input);
+ if (url.includes('/contacts/check/')) {
+ lookups.push(url.split('/contacts/check/')[1]);
+ return Promise.reject(new TypeError('Failed to fetch'));
+ }
+ return defaultFetch(input);
+ }) as typeof fetch;
+ const { container } = renderComponent();
+ const textarea = await openBulkTab();
+ rtl.fireEvent.change(textarea, { target: { value: '911111111111\n912222222222' } });
+ rtl.fireEvent.click(rtl.screen.getByRole('button', { name: /Start Batch Check/i }));
+
+ await rtl.screen.findByText('Batch stopped', { selector: 'strong' });
+ const notice = container.querySelector('.nc-batch-stopped')?.textContent ?? '';
+ assert.match(notice, /The gateway did not answer\. Stopped at number 1 of 2\./);
+ assert.deepEqual(lookups, ['911111111111']);
+ assert.equal(rtl.screen.queryByText(/Completed checking/), null);
+});
+
test('NumberChecker: a refusal on the last number says so instead of counting numbers left unsent', async () => {
const lookups = stubLookups(number =>
number === '912222222222' ? jsonResponse({ message: 'Rate limit exceeded (HTTP 429)' }, 429) : registered(number),
@@ -553,6 +576,20 @@ test('NumberChecker: a lookup error that is not a gateway refusal fails that num
assert.equal(container.querySelector('.nc-batch-stopped'), null);
});
+test('NumberChecker: a run in which every lookup failed is not reported as completed', async () => {
+ const lookups = stubLookups(() => jsonResponse({ message: 'engine hiccup' }, 500));
+ const { container } = renderComponent();
+ const textarea = await openBulkTab();
+ rtl.fireEvent.change(textarea, { target: { value: '911111111111\n912222222222' } });
+ rtl.fireEvent.click(rtl.screen.getByRole('button', { name: /Start Batch Check/i }));
+
+ await rtl.screen.findByText('Check failed', {}, { timeout: 3000 });
+ assert.deepEqual(lookups, ['911111111111', '912222222222']);
+ assert.equal(statValue('Failed'), '2');
+ assert.equal(rtl.screen.queryByText(/Completed checking/), null);
+ assert.equal(container.querySelector('.nc-batch-stopped'), null);
+});
+
// The Clipboard API is missing over plain HTTP on a LAN address, where the Copy button used to throw
// before it could report anything. The house helper falls back to the textarea route.
test('NumberChecker: Copy works where navigator.clipboard does not exist', async t => {
diff --git a/dashboard/src/pages/NumberChecker.tsx b/dashboard/src/pages/NumberChecker.tsx
index 7099cfd7a..a9b3b0129 100644
--- a/dashboard/src/pages/NumberChecker.tsx
+++ b/dashboard/src/pages/NumberChecker.tsx
@@ -36,20 +36,32 @@ export type CheckStatus = 'registered' | 'unregistered' | 'failed';
export const NUMBER_CHECK_BATCH_MAX = 100;
interface BatchStop {
+ // 0 when the lookup got no HTTP answer at all.
status: number;
attempted: number;
total: number;
}
// What each stopping status means, so a single unanswered lookup is not reported as the gateway refusing.
+// The check route answers 400 only for a session that is not started, the same condition as a 409.
const STOP_REASON_KEYS: Record<number, string> = {
+ 400: 'numberChecker.stopped.reason409',
409: 'numberChecker.stopped.reason409',
429: 'numberChecker.stopped.reason429',
503: 'numberChecker.stopped.reason503',
};
+// The status of a lookup that fails every number after it alike, or undefined when only that number failed.
+// A rejected fetch carries no status: the gateway never answered.
+function lookupStopStatus(err: unknown): number | undefined {
+ const status = (err as { status?: unknown } | null)?.status;
+ if (typeof status !== 'number') return 0;
+ return status === 400 || isGatewayRefusal(err) ? status : undefined;
+}
+
// `attempted` counts the lookup that stopped the run, which is the last one sent; only the rest were never sent.
function batchStopMessage(t: TFunction, { status, attempted, total }: BatchStop): string {
+ if (status === 0) return t('numberChecker.stopped.noAnswer', { attempted, total });
const reason = t(STOP_REASON_KEYS[status] ?? 'numberChecker.stopped.reasonOther');
const unsent = total - attempted;
return unsent > 0
@@ -291,10 +303,12 @@ export function NumberChecker() {
});
setBatchResults([...results]);
- // The gateway keeps refusing this route for the rest of its window, so every number after this one
- // would only become a false "Failed" row (and spend more of the limit).
- if (isGatewayRefusal(err)) {
- refusedWith = (err as { status: number }).status;
+ // The gateway keeps refusing this route for the rest of its window, a stopped session or an unreachable
+ // gateway fails every later number too, so each would only become a false "Failed" row (and spend more
+ // of the limit).
+ const stopStatus = lookupStopStatus(err);
+ if (stopStatus !== undefined) {
+ refusedWith = stopStatus;
setBatchProgress({ current: i + 1, total: numbers.length });
break;
}
@@ -317,6 +331,10 @@ export function NumberChecker() {
toast.error(t('numberChecker.bulk.stoppedTitle'), batchStopMessage(t, stop));
return;
}
+ if (results.every(r => r.status === 'failed')) {
+ toast.error(t('numberChecker.toast.checkFailed'), results[results.length - 1].error ?? undefined);
+ return;
+ }
toast.success(t('numberChecker.toast.completed', { count: results.length }));
};