feat(MED-85): add logging for medipost response error xml

This commit is contained in:
2025-08-28 12:25:18 +03:00
parent a37c4cad9c
commit b4985afdf0
3 changed files with 50 additions and 12 deletions

View File

@@ -736,20 +736,38 @@ export async function sendOrderToMedipost({
try { try {
await sendPrivateMessage(orderXml); await sendPrivateMessage(orderXml);
await createMedipostActionLog({
action: 'send_order_to_medipost',
xml: orderXml,
hasAnalysisResults: false,
medusaOrderId,
});
} catch (e) { } catch (e) {
const isMedipostError = e instanceof MedipostValidationError; const isMedipostError = e instanceof MedipostValidationError;
await logMedipostDispatch({ if (isMedipostError) {
medusaOrderId, await logMedipostDispatch({
isSuccess: false, medusaOrderId,
isMedipostError, isSuccess: false,
errorMessage: isMedipostError ? e.response : undefined, isMedipostError,
}); errorMessage: e.response,
});
await createMedipostActionLog({
action: 'send_order_to_medipost',
xml: orderXml,
hasAnalysisResults: false,
medusaOrderId,
responseXml: e.response,
hasError: true,
});
} else {
await logMedipostDispatch({
medusaOrderId,
isSuccess: false,
isMedipostError,
});
await createMedipostActionLog({
action: 'send_order_to_medipost',
xml: orderXml,
hasAnalysisResults: false,
medusaOrderId,
hasError: true,
});
}
throw e; throw e;
} }
await logMedipostDispatch({ await logMedipostDispatch({
@@ -757,6 +775,12 @@ export async function sendOrderToMedipost({
isSuccess: true, isSuccess: true,
isMedipostError: false, isMedipostError: false,
}); });
await createMedipostActionLog({
action: 'send_order_to_medipost',
xml: orderXml,
hasAnalysisResults: false,
medusaOrderId,
});
await updateOrderStatus({ medusaOrderId, orderStatus: 'PROCESSING' }); await updateOrderStatus({ medusaOrderId, orderStatus: 'PROCESSING' });
} }
@@ -830,6 +854,8 @@ export async function createMedipostActionLog({
xml, xml,
hasAnalysisResults = false, hasAnalysisResults = false,
medusaOrderId, medusaOrderId,
responseXml,
hasError = false,
}: { }: {
action: action:
| 'send_order_to_medipost' | 'send_order_to_medipost'
@@ -839,6 +865,8 @@ export async function createMedipostActionLog({
xml: string; xml: string;
hasAnalysisResults?: boolean; hasAnalysisResults?: boolean;
medusaOrderId?: string | null; medusaOrderId?: string | null;
responseXml?: string | null;
hasError?: boolean;
}) { }) {
await getSupabaseServerAdminClient() await getSupabaseServerAdminClient()
.schema('medreport') .schema('medreport')
@@ -848,6 +876,8 @@ export async function createMedipostActionLog({
xml, xml,
has_analysis_results: hasAnalysisResults, has_analysis_results: hasAnalysisResults,
medusa_order_id: medusaOrderId, medusa_order_id: medusaOrderId,
response_xml: responseXml,
has_error: hasError,
}) })
.select('id') .select('id')
.throwOnError(); .throwOnError();

View File

@@ -1196,18 +1196,24 @@ export type Database = {
has_analysis_results: boolean has_analysis_results: boolean
created_at: string created_at: string
medusa_order_id: string medusa_order_id: string
response_xml: string
has_error: boolean
} }
Insert: { Insert: {
action: string action: string
xml: string xml: string
has_analysis_results: boolean has_analysis_results: boolean
medusa_order_id: string medusa_order_id: string
response_xml: string
has_error: boolean
} }
Update: { Update: {
action?: string action?: string
xml?: string xml?: string
has_analysis_results?: boolean has_analysis_results?: boolean
medusa_order_id?: string medusa_order_id?: string
response_xml?: string
has_error?: boolean
} }
} }
medreport_product_groups: { medreport_product_groups: {

View File

@@ -0,0 +1,2 @@
ALTER TABLE medreport.medipost_actions ADD COLUMN response_xml VARCHAR(131072);
ALTER TABLE medreport.medipost_actions ADD COLUMN has_error BOOLEAN NOT NULL DEFAULT FALSE;