Align DoListAsnad with Hamkar (4 args) and treat empty ERROR as [].

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-05 11:18:37 +03:30
co-authored by Cursor
parent 1ac23e13c1
commit 3ab102ddae
3 changed files with 49 additions and 19 deletions
@@ -20,6 +20,11 @@ export type TahesabCallOptions = {
method?: 'GET' | 'POST';
allowInsecureTls?: boolean;
timeoutMs?: number;
/**
* اگر ته‌حساب با فیلد ERROR و متن منطبق جواب داد، به‌جای ۵۰۲
* مقدار خالی ([] ) برگردان — مثل «رکوردی یافت نشد» در DoListAsnad.
*/
emptyResultOnError?: RegExp;
};
function extractTahesabError(json: unknown, text: string): string {
@@ -109,6 +114,17 @@ export class TahesabHttpClient {
// بعضی متدها با ۲۰۰ و فیلد ERROR برمی‌گردند
if (json && typeof json === 'object' && 'ERROR' in (json as object)) {
const detail = extractTahesabError(json, text);
if (
detail &&
opts.emptyResultOnError &&
opts.emptyResultOnError.test(detail)
) {
this.logger.debug(
`Tahesab ${path} empty-on-error: ${detail.slice(0, 120)}`,
);
resolve([] as T);
return;
}
reject(
new BadGatewayException(
detail ? `ته‌حساب: ${detail}` : `خطای ته‌حساب برای ${path}`,