forked from Shared/esg
final update on moallm client
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { AxiosError, AxiosInstance } from 'axios';
|
||||
import { createOutboundAxiosInstance } from '../../common/helpers/http-client.helper';
|
||||
import {
|
||||
CentInsurApiResponse,
|
||||
describeCentInsurResponse,
|
||||
getCentInsurProviderError,
|
||||
} from '../../common/helpers/centinsur-response.helper';
|
||||
import { getSayahProviderError } from '../../common/helpers/sayah-response.helper';
|
||||
import { InquiryType } from '../../common/enums/inquiry-type.enum';
|
||||
import { ProviderName } from '../../common/enums/provider-name.enum';
|
||||
@@ -131,6 +136,12 @@ export abstract class LegacyApiProvider extends BaseProvider<
|
||||
|
||||
const body = response.data;
|
||||
|
||||
if ('IsSucceed' in body) {
|
||||
this.nestLogger.log(
|
||||
`${inquiryType} provider response | http=${response.status} | ${describeCentInsurResponse(body)}`,
|
||||
);
|
||||
}
|
||||
|
||||
// Handle Sayah/Sheba API format (ReturnValue/HasError)
|
||||
if ('ReturnValue' in body || 'HasError' in body) {
|
||||
const providerError = getSayahProviderError(body);
|
||||
@@ -142,11 +153,14 @@ export abstract class LegacyApiProvider extends BaseProvider<
|
||||
|
||||
// Handle CentInsur API format (IsSucceed/Result)
|
||||
if ('IsSucceed' in body) {
|
||||
if (!body.IsSucceed) {
|
||||
throw this.formatProviderError(
|
||||
body.Result?.ErrorMessage ?? 'Request failed',
|
||||
'API_ERROR',
|
||||
const providerError = getCentInsurProviderError(body, inquiryType);
|
||||
if (providerError) {
|
||||
this.nestLogger.warn(
|
||||
`${inquiryType} provider business failure | ${describeCentInsurResponse(body)}`,
|
||||
);
|
||||
throw this.formatProviderError(providerError.message, providerError.code, undefined, {
|
||||
providerTrackingCode: providerError.providerTrackingCode,
|
||||
});
|
||||
}
|
||||
return { raw: body };
|
||||
}
|
||||
@@ -172,11 +186,13 @@ export abstract class LegacyApiProvider extends BaseProvider<
|
||||
}
|
||||
|
||||
// Check for CentInsur format error
|
||||
if (data && 'IsSucceed' in data && !data.IsSucceed) {
|
||||
throw this.formatProviderError(
|
||||
data.Result?.ErrorMessage ?? error.message,
|
||||
String(error.response?.status ?? 'API_ERROR'),
|
||||
);
|
||||
if (data && 'IsSucceed' in data) {
|
||||
const providerError = getCentInsurProviderError(data, inquiryType);
|
||||
if (providerError) {
|
||||
throw this.formatProviderError(providerError.message, providerError.code, undefined, {
|
||||
providerTrackingCode: providerError.providerTrackingCode,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
throw this.formatProviderError(
|
||||
|
||||
Reference in New Issue
Block a user