forked from Yara724/api
Fixed smsApiKey index error and err handling in ESG
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user