Fix Tahesab health check to match Postman root-endpoint flow.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-03 16:45:04 +03:30
co-authored by Cursor
parent c322a24424
commit 17628722d3
3 changed files with 109 additions and 33 deletions
@@ -251,12 +251,7 @@ export class TahesabConnectionsService {
async test(organizationId: string, id: string) {
const { row, api } = await this.getApi(organizationId, id);
try {
let result: unknown;
try {
result = await api.checkHealthSsl();
} catch {
result = await api.checkHealthNoSsl();
}
const result = await api.checkHealth();
const updated = await this.prisma.accountingConnection.update({
where: { id: row.id },
data: {
@@ -268,15 +263,20 @@ export class TahesabConnectionsService {
return { ok: true, connection: this.toDto(updated), health: result };
} catch (err) {
const message = (err as Error).message ?? 'خطای ناشناخته';
const hint =
/مهلت اتصال|timeout/i.test(message) && !row.allowInsecureTls && /^https:/i.test(row.baseUrl)
? ' اگر گواهی ته‌حساب خودامضاست، «پذیرش گواهی SSL خودامضا» را فعال کنید.'
: '';
const full = `${message}${hint}`.slice(0, 500);
const updated = await this.prisma.accountingConnection.update({
where: { id: row.id },
data: {
lastHealthAt: new Date(),
lastHealthOk: false,
lastError: message.slice(0, 500),
lastError: full,
},
});
return { ok: false, connection: this.toDto(updated), error: message };
return { ok: false, connection: this.toDto(updated), error: full };
}
}
}