1
0
forked from Yara724/api

Fixed smsApiKey index error and err handling in ESG

This commit is contained in:
SepehrYahyaee
2026-06-21 12:18:08 +03:30
parent 570fa865de
commit d0e7694374
6 changed files with 56 additions and 28 deletions

View File

@@ -20,6 +20,9 @@ import { firstValueFrom } from "rxjs";
@Injectable()
export class SandHubService {
private static readonly ESG_INQUIRY_UNAVAILABLE_MESSAGE =
"استعلام در دسترس نیست";
private readonly logger = new Logger(SandHubService.name);
private loginToken: string | null = null;
private tokenExpiry: Date | null = null;
@@ -528,17 +531,13 @@ export class SandHubService {
if (!raw) return raw;
if (raw?.success === false) {
this.logger.warn(
"ESG policyByPlate inquiry returned success=false",
raw,
);
return {
Error: {
Message:
raw?.error?.message ||
raw?.message ||
"ESG policyByPlate inquiry returned an error",
Code: raw?.error?.code || raw?.error?.providerCode || "ESG_INQUIRY_ERROR",
ProviderMessage: raw?.error?.providerMessage,
ProviderCode: raw?.error?.providerCode,
TrackingCode: raw?.trackingCode,
Conflict: raw?.error?.conflict,
Message: SandHubService.ESG_INQUIRY_UNAVAILABLE_MESSAGE,
},
};
}
@@ -622,10 +621,9 @@ export class SandHubService {
private mapEsgPersonInquiryToOldFormat(raw: any): Record<string, unknown> {
if (raw?.success === false) {
throw new NotFoundException(
raw?.error?.message ||
raw?.message ||
"Personal inquiry failed: Record not found for the given national code and birth date.",
this.logger.warn("ESG person inquiry returned success=false", raw);
throw new BadRequestException(
SandHubService.ESG_INQUIRY_UNAVAILABLE_MESSAGE,
);
}
@@ -648,10 +646,9 @@ export class SandHubService {
private mapEsgShebaInquiryToOldFormat(raw: any): Record<string, unknown> {
if (raw?.success === false) {
this.logger.warn("ESG sheba inquiry returned success=false", raw);
throw new BadRequestException(
raw?.error?.message ||
raw?.message ||
"Sheba ID validation failed. The provided Sheba ID does not match the national ID.",
SandHubService.ESG_INQUIRY_UNAVAILABLE_MESSAGE,
);
}