feat(MED-85): create logs of sending order to medipost success/error

This commit is contained in:
2025-08-25 12:22:29 +03:00
parent 828f32ee81
commit da8b5aa59f
3 changed files with 57 additions and 18 deletions

View File

@@ -44,6 +44,8 @@ import { StoreOrder } from '@medusajs/types';
import { listProducts } from '@lib/data/products';
import { listRegions } from '@lib/data/regions';
import { getAnalysisElementMedusaProductIds } from '@/utils/medusa-product';
import { MedipostValidationError } from './medipost/MedipostValidationError';
import { logMedipostDispatch } from './audit.service';
const BASE_URL = process.env.MEDIPOST_URL!;
const USER = process.env.MEDIPOST_USER!;
@@ -63,14 +65,14 @@ export async function validateMedipostResponse(response: string, { canHaveEmptyC
if (canHaveEmptyCode) {
if (code && code !== 0) {
console.error("Bad response", response);
throw new Error(`Medipost response is invalid`);
throw new MedipostValidationError(response);
}
return;
}
if (typeof code !== 'number' || (code !== 0 && !canHaveEmptyCode)) {
console.error("Bad response", response);
throw new Error(`Medipost response is invalid`);
throw new MedipostValidationError(response);
}
}
@@ -704,7 +706,22 @@ export async function sendOrderToMedipost({
comment: '',
});
await sendPrivateMessage(orderXml);
try {
await sendPrivateMessage(orderXml);
} catch (e) {
await logMedipostDispatch({
medusaOrderId,
isSuccess: false,
isMedipostError: e instanceof MedipostValidationError,
errorMessage: e instanceof MedipostValidationError ? e.response : undefined,
});
throw e;
}
await logMedipostDispatch({
medusaOrderId,
isSuccess: true,
isMedipostError: false,
});
await updateOrderStatus({ medusaOrderId, orderStatus: 'PROCESSING' });
}