Align DoListAsnad with Hamkar (4 args) and treat empty ERROR as [].
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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}`,
|
||||
|
||||
Reference in New Issue
Block a user