forked from Shared/esg
moallem all endpoints working
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import axios, { AxiosError, AxiosInstance } from 'axios';
|
||||
import { AxiosError, AxiosInstance } from 'axios';
|
||||
import { createOutboundAxiosInstance } from '../../common/helpers/http-client.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';
|
||||
import { ProviderExecutionContext } from '../../common/interfaces/inquiry-provider.interface';
|
||||
@@ -51,7 +53,7 @@ export abstract class LegacyApiProvider extends BaseProvider<
|
||||
) {
|
||||
super(config);
|
||||
this.providerConfig = config;
|
||||
this.httpClient = axios.create({
|
||||
this.httpClient = createOutboundAxiosInstance({
|
||||
timeout: config.timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -131,15 +133,9 @@ export abstract class LegacyApiProvider extends BaseProvider<
|
||||
|
||||
// Handle Sayah/Sheba API format (ReturnValue/HasError)
|
||||
if ('ReturnValue' in body || 'HasError' in body) {
|
||||
if (body.HasError) {
|
||||
// Format error message from Errors object
|
||||
const errorMessages = body.Errors
|
||||
? Object.entries(body.Errors).map(([code, field]) => `${field} (code: ${code})`).join(', ')
|
||||
: 'Request failed';
|
||||
throw this.formatProviderError(
|
||||
errorMessages,
|
||||
'SAYAH_ERROR',
|
||||
);
|
||||
const providerError = getSayahProviderError(body);
|
||||
if (providerError) {
|
||||
throw this.formatProviderError(providerError.message, providerError.code);
|
||||
}
|
||||
return { raw: body };
|
||||
}
|
||||
@@ -168,14 +164,11 @@ export abstract class LegacyApiProvider extends BaseProvider<
|
||||
const data = error.response?.data as LegacyProviderApiResponse | undefined;
|
||||
|
||||
// Check for Sayah/Sheba format error
|
||||
if (data && ('ReturnValue' in data || 'HasError' in data) && data.HasError) {
|
||||
const errorMessages = data.Errors
|
||||
? Object.entries(data.Errors).map(([code, field]) => `${field} (code: ${code})`).join(', ')
|
||||
: error.message;
|
||||
throw this.formatProviderError(
|
||||
errorMessages,
|
||||
String(error.response?.status ?? 'SAYAH_ERROR'),
|
||||
);
|
||||
if (data && ('ReturnValue' in data || 'HasError' in data)) {
|
||||
const providerError = getSayahProviderError(data);
|
||||
if (providerError) {
|
||||
throw this.formatProviderError(providerError.message, providerError.code);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for CentInsur format error
|
||||
|
||||
Reference in New Issue
Block a user