Fix Tahesab ByCode list body key causing 502 on range search.
Use Dolistmoshtari as documented and surface upstream error text in the UI. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -22,6 +22,17 @@ export type TahesabCallOptions = {
|
||||
timeoutMs?: number;
|
||||
};
|
||||
|
||||
function extractTahesabError(json: unknown, text: string): string {
|
||||
if (json && typeof json === 'object') {
|
||||
const o = json as Record<string, unknown>;
|
||||
const err = o.ERROR ?? o.Error ?? o.error ?? o.message ?? o.Message;
|
||||
if (typeof err === 'string' && err.trim()) return err.trim().slice(0, 300);
|
||||
if (Array.isArray(err) && err.length) return String(err[0]).slice(0, 300);
|
||||
}
|
||||
const trimmed = text.trim();
|
||||
return trimmed ? trimmed.slice(0, 300) : '';
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class TahesabHttpClient {
|
||||
private readonly logger = new Logger(TahesabHttpClient.name);
|
||||
@@ -85,9 +96,22 @@ export class TahesabHttpClient {
|
||||
this.logger.warn(
|
||||
`Tahesab ${method} ${path} → ${status}: ${text.slice(0, 400)}`,
|
||||
);
|
||||
const detail = extractTahesabError(json, text);
|
||||
reject(
|
||||
new BadGatewayException(
|
||||
`پاسخ نامعتبر تهحساب (${status}) برای ${path}`,
|
||||
detail
|
||||
? `تهحساب (${status}): ${detail}`
|
||||
: `پاسخ نامعتبر تهحساب (${status}) برای ${path}`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
// بعضی متدها با ۲۰۰ و فیلد ERROR برمیگردند
|
||||
if (json && typeof json === 'object' && 'ERROR' in (json as object)) {
|
||||
const detail = extractTahesabError(json, text);
|
||||
reject(
|
||||
new BadGatewayException(
|
||||
detail ? `تهحساب: ${detail}` : `خطای تهحساب برای ${path}`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
|
||||
@@ -183,9 +183,10 @@ export class TahesabApi {
|
||||
}
|
||||
|
||||
doListMoshtariByCode(fromCode: number, toCode: number) {
|
||||
// OpenAPI/Postman: کلید body برای ByCode دقیقاً «Dolistmoshtari» است (حساس به حروف)
|
||||
return this.call(
|
||||
'DoListMoshtari-ByCode',
|
||||
'DoListMoshtari',
|
||||
'Dolistmoshtari',
|
||||
[fromCode, toCode],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user