forked from Shared/esg
Add health check and retry logic and circuit breaker
This commit is contained in:
@@ -100,19 +100,19 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
context: ProviderExecutionContext,
|
||||
): Promise<LegacyInquiryResult> {
|
||||
if (inquiryType === InquiryType.PERSON) {
|
||||
return this.inquireCivilRegistration(payload as CivilRegistrationPayload);
|
||||
return this.inquireCivilRegistration(payload as CivilRegistrationPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.POSTAL_CODE) {
|
||||
return this.inquirePostalCode(payload as PostalCodePayload);
|
||||
return this.inquirePostalCode(payload as PostalCodePayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.SHAHKAR) {
|
||||
return this.inquireShahkar(payload as ShahkarPayload);
|
||||
return this.inquireShahkar(payload as ShahkarPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.SHEBA) {
|
||||
return this.inquireSayah(payload as SayahPayload);
|
||||
return this.inquireSayah(payload as SayahPayload, context.signal);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.CAR_BY_PLATE) {
|
||||
@@ -121,6 +121,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
payload as CarPlatePayload,
|
||||
(message, code, fallback, extras) =>
|
||||
this.formatProviderError(message, code, fallback, extras as never),
|
||||
context.signal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,6 +131,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
payload as CarChassisPayload,
|
||||
(message, code, fallback, extras) =>
|
||||
this.formatProviderError(message, code, fallback, extras as never),
|
||||
context.signal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -139,13 +141,14 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
payload as CarPlatePayload,
|
||||
(message, code, fallback, extras) =>
|
||||
this.formatProviderError(message, code, fallback, extras as never),
|
||||
context.signal,
|
||||
);
|
||||
}
|
||||
|
||||
return super.callProvider(inquiryType, payload, context);
|
||||
}
|
||||
|
||||
private async inquirePostalCode(payload: PostalCodePayload): Promise<{ raw: unknown }> {
|
||||
private async inquirePostalCode(payload: PostalCodePayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const postalCode = this.getRequiredString(
|
||||
payload.postalCode ?? payload.PostalCode,
|
||||
'postalCode',
|
||||
@@ -157,6 +160,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
InquiryType.POSTAL_CODE,
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
signal,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -166,6 +170,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
params: { PostalCode: postalCode },
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
timeout: this.moallemConfig.timeout,
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -183,6 +188,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
|
||||
private async inquireCivilRegistration(
|
||||
payload: CivilRegistrationPayload,
|
||||
signal?: AbortSignal,
|
||||
): Promise<PersonInquiryResult> {
|
||||
const nationalCode = this.getRequiredString(
|
||||
payload.nationalCode ?? payload.NIN,
|
||||
@@ -209,6 +215,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
},
|
||||
timeout: this.moallemConfig.timeout,
|
||||
responseType: 'text',
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -234,7 +241,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private async inquireShahkar(payload: ShahkarPayload): Promise<{ raw: unknown }> {
|
||||
private async inquireShahkar(payload: ShahkarPayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const nationalCode = this.getRequiredString(
|
||||
payload.nationalCode ?? payload.nationalCod ?? payload.NationalCod,
|
||||
'nationalCode',
|
||||
@@ -259,6 +266,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
},
|
||||
timeout: this.moallemConfig.timeout,
|
||||
responseType: 'text',
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -291,7 +299,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private async inquireSayah(payload: SayahPayload): Promise<{ raw: unknown }> {
|
||||
private async inquireSayah(payload: SayahPayload, signal?: AbortSignal): Promise<{ raw: unknown }> {
|
||||
const accountOwnerType = payload.accountOwnerType ?? '1';
|
||||
const nationalId = payload.nationalCode ?? '';
|
||||
const legalId = payload.legalId ?? null;
|
||||
@@ -303,6 +311,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
InquiryType.SHEBA,
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
signal,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -320,6 +329,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: this.moallemConfig.timeout,
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user