forked from Shared/esg
Implement normalized error handling with Persian translations across all exception types, replace legacy NestJS exceptions with AppException, and add unit, integration, and smoke tests. - Add error catalog with gateway-owned codes and Persian messages - Introduce AppException wrapping normalized error envelopes - Add translateError helper for automatic messageFa population - Remove claims module and update provider error normalization - Add unit tests for error contracts and helper functions - Add integration tests for admin and inquiry endpoints - Add smoke tests for real provider connectivity - Add test support utilities (auth mocks, assertions, app factory)
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { NormalizedErrorDto } from '../../src/common/dto/normalized-error.dto';
|
|
import { ProviderName } from '../../src/common/enums/provider-name.enum';
|
|
import { buildNormalizedError } from '../../src/common/constants/error-messages';
|
|
|
|
export function successfulProviderResult(data: unknown = { raw: { ok: true } }) {
|
|
return {
|
|
data,
|
|
provider: ProviderName.HAMTA,
|
|
duration: 12,
|
|
};
|
|
}
|
|
|
|
export function normalizedProviderError(error: NormalizedErrorDto): Error {
|
|
const err = new Error(error.message);
|
|
(err as Error & { normalizedError: NormalizedErrorDto }).normalizedError = error;
|
|
return err;
|
|
}
|
|
|
|
export const providerErrorCases = [
|
|
{
|
|
name: 'provider timeout',
|
|
code: 'PROVIDER_TIMEOUT',
|
|
error: buildNormalizedError('PROVIDER_TIMEOUT', {
|
|
message: 'Provider request timed out',
|
|
providerCode: 'ETIMEDOUT',
|
|
}),
|
|
},
|
|
{
|
|
name: 'provider HTTP 4xx',
|
|
code: 'PROVIDER_BAD_RESPONSE',
|
|
error: buildNormalizedError('PROVIDER_BAD_RESPONSE', {
|
|
message: 'Provider returned HTTP 400',
|
|
providerCode: '400',
|
|
}),
|
|
},
|
|
{
|
|
name: 'provider HTTP 5xx',
|
|
code: 'PROVIDER_BAD_RESPONSE',
|
|
error: buildNormalizedError('PROVIDER_BAD_RESPONSE', {
|
|
message: 'Provider returned HTTP 500',
|
|
providerCode: '500',
|
|
}),
|
|
},
|
|
{
|
|
name: 'provider business error',
|
|
code: 'INQUIRY_NO_MATCH',
|
|
error: buildNormalizedError('INQUIRY_NO_MATCH', {
|
|
message: 'Inquiry returned no matching result',
|
|
providerCode: 'NO_MATCH',
|
|
}),
|
|
},
|
|
{
|
|
name: 'malformed provider response',
|
|
code: 'PROVIDER_BAD_RESPONSE',
|
|
error: buildNormalizedError('PROVIDER_BAD_RESPONSE', {
|
|
message: 'Provider response could not be parsed',
|
|
providerCode: 'MALFORMED_RESPONSE',
|
|
}),
|
|
},
|
|
];
|