feat(api): add async error handling to critical module handlers
Wrap async operations at application layer boundaries with proper try/catch, LoggerService logging, and domain exceptions: - UploadMediaHandler: mediaStorage.upload() error boundary - ExportUserDataHandler: Promise.all() error logging - ForceDeleteUserHandler: $transaction error logging - LoginUserHandler: token generation error boundary - RefreshTokenHandler: token rotation error boundary - CreatePaymentHandler: payment gateway call error boundary Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -65,13 +65,24 @@ export class CreatePaymentHandler implements ICommandHandler<CreatePaymentComman
|
||||
|
||||
// Get payment gateway and create URL
|
||||
const gateway = this.gatewayFactory.getGateway(command.provider);
|
||||
const { paymentUrl, providerTxId } = await gateway.createPaymentUrl({
|
||||
orderId: paymentId,
|
||||
amountVND: command.amountVND,
|
||||
description: command.description,
|
||||
returnUrl: command.returnUrl,
|
||||
ipAddress: command.ipAddress,
|
||||
});
|
||||
let paymentUrl: string;
|
||||
let providerTxId: string;
|
||||
try {
|
||||
({ paymentUrl, providerTxId } = await gateway.createPaymentUrl({
|
||||
orderId: paymentId,
|
||||
amountVND: command.amountVND,
|
||||
description: command.description,
|
||||
returnUrl: command.returnUrl,
|
||||
ipAddress: command.ipAddress,
|
||||
}));
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Payment gateway ${command.provider} failed for order ${paymentId}: ${error instanceof Error ? error.message : error}`,
|
||||
error instanceof Error ? error.stack : undefined,
|
||||
'CreatePaymentHandler',
|
||||
);
|
||||
throw new ValidationException('Không thể tạo liên kết thanh toán, vui lòng thử lại');
|
||||
}
|
||||
|
||||
// Mark processing and save
|
||||
payment.markProcessing(providerTxId);
|
||||
|
||||
Reference in New Issue
Block a user