forked from Shared/esg
Add health check and retry logic and circuit breaker
This commit is contained in:
@@ -21,6 +21,7 @@ export class CentInsurCarPolicyClient {
|
||||
config: ProviderEnvConfig,
|
||||
inquiryType: InquiryType,
|
||||
chassisNo: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Record<string, string>> {
|
||||
return this.callSoap(
|
||||
config,
|
||||
@@ -28,6 +29,7 @@ export class CentInsurCarPolicyClient {
|
||||
InquiryType.POLICY_BY_CHASSIS,
|
||||
'CIIWSPolicyChassis',
|
||||
{ ChassisNo: chassisNo },
|
||||
signal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -35,6 +37,7 @@ export class CentInsurCarPolicyClient {
|
||||
config: ProviderEnvConfig,
|
||||
inquiryType: InquiryType,
|
||||
plate: CarPlateSoapFields,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Record<string, string>> {
|
||||
return this.callSoap(
|
||||
config,
|
||||
@@ -47,6 +50,7 @@ export class CentInsurCarPolicyClient {
|
||||
Plk3: plate.plk3,
|
||||
PlkSrl: plate.plksrl,
|
||||
},
|
||||
signal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,6 +58,7 @@ export class CentInsurCarPolicyClient {
|
||||
config: ProviderEnvConfig,
|
||||
inquiryType: InquiryType,
|
||||
nationalCode: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Record<string, string>> {
|
||||
return this.callSoap(
|
||||
config,
|
||||
@@ -61,6 +66,7 @@ export class CentInsurCarPolicyClient {
|
||||
InquiryType.POLICY_BY_NATIONAL_CODE,
|
||||
'CIIWSPolicyNationalId',
|
||||
{ NationalId: nationalCode },
|
||||
signal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,6 +76,7 @@ export class CentInsurCarPolicyClient {
|
||||
fallbackInquiryType: InquiryType,
|
||||
methodName: string,
|
||||
fields: Record<string, string>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Record<string, string>> {
|
||||
const inquiryConfig = this.resolveInquiryConfig(config, inquiryType, fallbackInquiryType);
|
||||
|
||||
@@ -93,6 +100,7 @@ export class CentInsurCarPolicyClient {
|
||||
},
|
||||
timeout: config.timeout,
|
||||
responseType: 'text',
|
||||
signal,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -100,9 +108,10 @@ export class CentInsurCarPolicyClient {
|
||||
const providerError = getCarPolicyProviderError(response.data, policy);
|
||||
if (providerError) {
|
||||
const error = new Error(providerError.message);
|
||||
(error as Error & { normalizedError: { code: string; message: string } }).normalizedError = {
|
||||
(error as Error & { normalizedError: { code: string; message: string; providerCode?: string } }).normalizedError = {
|
||||
code: providerError.code,
|
||||
message: providerError.message,
|
||||
providerCode: providerError.providerCode,
|
||||
};
|
||||
throw error;
|
||||
}
|
||||
@@ -110,11 +119,13 @@ export class CentInsurCarPolicyClient {
|
||||
return policy;
|
||||
} catch (error) {
|
||||
if (error instanceof AxiosError) {
|
||||
const providerStatus = String(error.response?.status ?? 'NETWORK_ERROR');
|
||||
const wrapped = new Error(error.message);
|
||||
(wrapped as Error & { normalizedError: { code: string; message: string } }).normalizedError =
|
||||
(wrapped as Error & { normalizedError: { code: string; message: string; providerCode?: string } }).normalizedError =
|
||||
{
|
||||
code: String(error.response?.status ?? 'NETWORK_ERROR'),
|
||||
code: error.response ? 'PROVIDER_ERROR' : providerStatus,
|
||||
message: error.message,
|
||||
providerCode: error.response ? providerStatus : undefined,
|
||||
};
|
||||
throw wrapped;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user