final update on moallm client

This commit is contained in:
2026-06-15 10:23:00 +03:30
parent fac6142483
commit 1b7f678538
17 changed files with 394 additions and 70 deletions

View File

@@ -126,6 +126,8 @@ export abstract class BaseProvider<TRequest = unknown, TResponse = unknown>
message: partial.message ?? 'Provider request failed',
providerMessage: partial.providerMessage,
providerCode: partial.providerCode,
providerTrackingCode: partial.providerTrackingCode,
details: partial.details,
};
}
@@ -133,6 +135,7 @@ export abstract class BaseProvider<TRequest = unknown, TResponse = unknown>
providerMessage?: string,
providerCode?: string,
fallbackMessage = 'Provider request failed',
extras?: Pick<NormalizedErrorDto, 'providerTrackingCode' | 'details'>,
): Error {
const message = providerMessage?.trim() || fallbackMessage;
const code = providerCode?.trim() || 'PROVIDER_ERROR';
@@ -141,6 +144,7 @@ export abstract class BaseProvider<TRequest = unknown, TResponse = unknown>
message,
providerMessage: message,
providerCode: code,
...extras,
});
const err = new Error(message);
(err as Error & { normalizedError: NormalizedErrorDto }).normalizedError = normalized;

View File

@@ -6,6 +6,11 @@ import {
getSayahProviderError,
SayahApiResponse,
} from '../../common/helpers/sayah-response.helper';
import {
describeShahkarResponse,
getShahkarProviderError,
parseShahkarInqueryResult,
} from '../../common/helpers/shahkar-response.helper';
import { InquiryType } from '../../common/enums/inquiry-type.enum';
import { ProviderName } from '../../common/enums/provider-name.enum';
import { ProviderEnvConfig } from '../../config/configuration';
@@ -210,14 +215,22 @@ export class HamtaProvider extends LegacyApiProvider {
}),
);
const result = this.extractSoapValue(response.data, 'ShahkarInqueryResult');
const shahkarFields = parseShahkarInqueryResult(response.data);
const providerError = getShahkarProviderError(shahkarFields);
if (providerError) {
this.nestLogger.warn(
`SHAHKAR provider business failure | ${describeShahkarResponse(shahkarFields)}`,
);
throw this.formatProviderError(providerError.message, providerError.code, undefined, {
providerTrackingCode: providerError.providerTrackingCode,
});
}
return {
raw: {
nationalCode,
mobileNo,
result,
soap: response.data,
...shahkarFields,
},
};
} catch (error) {

View File

@@ -7,6 +7,11 @@ import {
getCivilRegistrationProviderError,
parseCiiEstelamResult,
} from '../../common/helpers/soap-civil-registration.helper';
import {
getShahkarProviderError,
parseShahkarInqueryResult,
describeShahkarResponse,
} from '../../common/helpers/shahkar-response.helper';
import {
getSayahProviderError,
SayahApiResponse,
@@ -218,14 +223,22 @@ export class MoallemProvider extends LegacyApiProvider {
}),
);
const result = this.extractSoapValue(response.data, 'ShahkarInqueryResult');
const shahkarFields = parseShahkarInqueryResult(response.data);
const providerError = getShahkarProviderError(shahkarFields);
if (providerError) {
this.nestLogger.warn(
`SHAHKAR provider business failure | ${describeShahkarResponse(shahkarFields)}`,
);
throw this.formatProviderError(providerError.message, providerError.code, undefined, {
providerTrackingCode: providerError.providerTrackingCode,
});
}
return {
raw: {
nationalCode,
mobileNo,
result,
soap: response.data,
...shahkarFields,
},
};
} catch (error) {

View File

@@ -2,10 +2,12 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import axios, { AxiosError } from 'axios';
import { mergeOutboundAxiosConfig } from '../../common/helpers/http-client.helper';
import { getSayahProviderError, SayahApiResponse } from '../../common/helpers/sayah-response.helper';
import {
getSayahProviderError,
SayahApiResponse,
} from '../../common/helpers/sayah-response.helper';
describeShahkarResponse,
getShahkarProviderError,
normalizeShahkarFields,
} from '../../common/helpers/shahkar-response.helper';
import { InquiryType } from '../../common/enums/inquiry-type.enum';
import { ProviderName } from '../../common/enums/provider-name.enum';
import { ProviderExecutionContext } from '../../common/interfaces/inquiry-provider.interface';
@@ -192,11 +194,22 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
);
const body = response.data;
const shahkarFields = normalizeShahkarFields(body as unknown as Record<string, unknown>);
const providerError = getShahkarProviderError(shahkarFields);
if (providerError) {
this.nestLogger.warn(
`SHAHKAR provider business failure | ${describeShahkarResponse(shahkarFields)}`,
);
throw this.formatProviderError(providerError.message, providerError.code, undefined, {
providerTrackingCode: providerError.providerTrackingCode,
});
}
return {
raw: {
nationalCode,
mobileNumber,
...body,
...shahkarFields,
},
};
} catch (error) {

View File

@@ -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(

View File

@@ -71,9 +71,10 @@ export class ProviderOrchestratorService {
const lastError = errors[errors.length - 1]!;
if (providers.length === 1) {
throw new InquiryException(lastError.message, lastError);
throw new InquiryException(lastError.message, lastError, undefined, providers[0]!.name);
}
const lastProvider = providers[providers.length - 1]!.name;
throw new InquiryException(
errors.map((error) => error.message).join('; '),
{
@@ -82,6 +83,8 @@ export class ProviderOrchestratorService {
providerMessage: lastError.providerMessage ?? lastError.message,
providerCode: lastError.providerCode ?? lastError.code,
},
undefined,
lastProvider,
);
}