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)
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { BaseInquiryResponseDto } from '../dto/base-inquiry-response.dto';
|
|
import { NormalizedErrorDto } from '../dto/normalized-error.dto';
|
|
import { translateError } from './translate-error.helper';
|
|
|
|
export function buildInquiryResponse<T = Record<string, unknown>>(params: {
|
|
success: boolean;
|
|
provider: string;
|
|
trackingCode: string;
|
|
message: string;
|
|
duration: number;
|
|
data?: T | null;
|
|
error?: NormalizedErrorDto | null;
|
|
}): BaseInquiryResponseDto<T> {
|
|
const error = params.success ? null : (params.error != null ? translateError(params.error) : null);
|
|
|
|
return {
|
|
success: params.success,
|
|
provider: params.provider,
|
|
trackingCode: params.trackingCode,
|
|
message: params.success ? params.message : undefined,
|
|
messageFa: undefined,
|
|
duration: params.duration,
|
|
data: params.success ? (params.data ?? null) : null,
|
|
error,
|
|
};
|
|
}
|
|
|
|
export function normalizeInquiryResponse<T = Record<string, unknown>>(
|
|
response: BaseInquiryResponseDto<T>,
|
|
): BaseInquiryResponseDto<T> {
|
|
return {
|
|
...response,
|
|
data: response.success ? (response.data ?? null) : null,
|
|
error: response.success ? null : (response.error ?? null),
|
|
};
|
|
}
|