manicanldes-backend/src/common/errors/commerce-errors.ts

725 lines
20 KiB
TypeScript

export const COMMERCE_ERRORS = {
PRODUCT_NOT_FOUND: [404, 'Product not found', 'Scoped product lookup failed'],
PRODUCT_NOT_PUBLISHABLE: [
409,
'Add an active priced variant before publishing',
'Product publish eligibility failed',
],
PRODUCT_ARCHIVED: [
409,
'Archived products cannot be edited',
'Archived product mutation rejected',
],
VARIANT_NOT_FOUND: [
404,
'Product variant not found',
'Scoped product variant lookup failed',
],
VARIANT_LIMIT: [
409,
'Product variant limit reached',
'Variant resource quota exceeded',
],
VARIANT_REQUIRED: [
409,
'A published product needs an active variant',
'Last sellable variant deactivation rejected',
],
GROUP_NOT_FOUND: [
404,
'Catalogue group not found',
'Scoped catalogue group lookup failed',
],
ADDRESS_NOT_FOUND: [
404,
'Address not found',
'Private address lookup failed',
],
ADDRESS_LIMIT: [
409,
'Address limit reached',
'Account address quota exceeded',
],
WAREHOUSE_NOT_FOUND: [
404,
'Warehouse not found',
'Scoped warehouse lookup failed',
],
STOCK_NOT_FOUND: [404, 'Stock item not found', 'Scoped stock lookup failed'],
STOCK_INSUFFICIENT: [
409,
'Insufficient available stock',
'Inventory availability check rejected operation',
],
STOCK_CAPACITY: [
409,
'Stock balance limit would be exceeded',
'Inventory integer bound rejected operation',
],
IDEMPOTENCY_CONFLICT: [
409,
'Idempotency key was used for a different request',
'Idempotency payload mismatch',
],
RESERVATION_NOT_FOUND: [
404,
'Stock reservation not found',
'Scoped reservation lookup failed',
],
RESERVATION_EXPIRED: [
409,
'Stock reservation has expired',
'Expired reservation commit rejected',
],
RESERVATION_CLOSED: [
409,
'Stock reservation is already closed',
'Invalid reservation state transition',
],
PRODUCT_UNAVAILABLE: [
409,
'Product variant is not available for reservation',
'Non-sellable variant reservation rejected',
],
SUPPLIER_NOT_FOUND: [
404,
'Supplier not found',
'Scoped supplier lookup failed',
],
MATERIAL_NOT_FOUND: [
404,
'Material not found',
'Scoped material lookup failed',
],
SUPPLIER_MATERIAL_NOT_FOUND: [
404,
'Supplier material is unavailable',
'Scoped supplier-material compatibility lookup failed',
],
PURCHASE_ORDER_NOT_FOUND: [
404,
'Purchase order not found',
'Scoped purchase order lookup failed',
],
PURCHASE_ORDER_STATE: [
409,
'Purchase order cannot change in its current state',
'Purchase order lifecycle transition rejected',
],
PURCHASE_ORDER_CURRENCY: [
409,
'Purchase order materials must use one currency',
'Supplier material quote currency mismatch',
],
PURCHASE_ORDER_MINIMUM: [
409,
'Order quantity is below the supplier minimum',
'Supplier material minimum order quantity rejected',
],
RECEIPT_NOT_FOUND: [
404,
'Goods receipt not found',
'Scoped goods receipt lookup failed',
],
RECEIPT_ORDER_STATE: [
409,
'Only issued purchase orders can receive goods',
'Receipt rejected for non-issued order',
],
RECEIPT_LINE_INVALID: [
409,
'Receipt line does not belong to this purchase order',
'Receipt purchase-order line mismatch',
],
RECEIPT_QUANTITY_LIMIT: [
409,
'Received quantity exceeds the outstanding order quantity',
'Receipt outstanding quantity exceeded',
],
RECEIPT_ALREADY_INSPECTED: [
409,
'Goods receipt has already been inspected',
'Duplicate receipt inspection rejected',
],
INSPECTION_LINES_INVALID: [
409,
'Inspect every receipt line exactly once',
'Inspection receipt-line set mismatch',
],
INSPECTION_QUANTITY_INVALID: [
409,
'Accepted and rejected quantities must equal the received quantity',
'Inspection quantity reconciliation failed',
],
INSPECTION_REASON_REQUIRED: [
409,
'Give a reason for rejected goods',
'Rejected receipt quantity lacked a reason',
],
INVOICE_NOT_FOUND: [
404,
'Supplier invoice not found',
'Scoped supplier invoice lookup failed',
],
INVOICE_ORDER_STATE: [
409,
'Only issued purchase orders can be invoiced',
'Supplier invoice rejected for non-issued order',
],
INVOICE_LINE_INVALID: [
409,
'Invoice line does not belong to this purchase order',
'Supplier invoice order-line mismatch',
],
INVOICE_QC_REQUIRED: [
409,
'Goods must pass quality inspection before invoicing',
'Supplier invoice line has no accepted receipt quantity',
],
INVOICE_QUANTITY_LIMIT: [
409,
'Invoice quantity exceeds accepted, uninvoiced goods',
'Supplier invoice accepted quantity exceeded',
],
INVOICE_NUMBER_CONFLICT: [
409,
'Invoice number is already recorded for this supplier',
'Supplier invoice number duplicate',
],
INVOICE_AMOUNT_LIMIT: [
409,
'Invoice amount exceeds the supported limit',
'Supplier invoice money column limit exceeded',
],
INVOICE_ALREADY_VOID: [
409,
'Supplier invoice is already void',
'Duplicate supplier invoice void rejected',
],
INVOICE_PAYMENT_EXISTS: [
409,
'Reverse active payments before voiding this invoice',
'Supplier invoice void blocked by active payment',
],
PAYMENT_NOT_FOUND: [
404,
'Supplier payment not found',
'Scoped supplier payment lookup failed',
],
PAYMENT_INVOICE_VOID: [
409,
'Cannot record payment for a void invoice',
'Supplier payment rejected for void invoice',
],
PAYMENT_AMOUNT_LIMIT: [
409,
'Payment exceeds the remaining invoice balance',
'Supplier payment balance exceeded',
],
PAYMENT_REFERENCE_CONFLICT: [
409,
'Payment reference is already recorded',
'Supplier payment reference duplicate',
],
PAYMENT_REPLAY_CONFLICT: [
409,
'Idempotency key was used for a different payment',
'Supplier payment idempotency payload mismatch',
],
PAYMENT_ALREADY_REVERSED: [
409,
'Supplier payment is already reversed',
'Duplicate supplier payment reversal rejected',
],
DOCUMENT_NOT_FOUND: [
404,
'Supplier document not found',
'Scoped supplier document lookup failed',
],
DOCUMENT_VERSION_NOT_FOUND: [
404,
'Document version not found',
'Scoped document version lookup failed',
],
DOCUMENT_CODE_CONFLICT: [
409,
'Document code is already used for this supplier',
'Supplier document code duplicate',
],
DOCUMENT_LIMIT: [
409,
'Supplier document limit reached',
'Supplier document resource quota exceeded',
],
DOCUMENT_VERSION_LIMIT: [
409,
'Document version limit reached',
'Supplier document version quota exceeded',
],
DOCUMENT_FILE_REQUIRED: [
400,
'PDF file is required',
'Supplier document upload lacked file',
],
DOCUMENT_FILE_TOO_LARGE: [
413,
'PDF exceeds the 2 MiB limit',
'Supplier document byte limit exceeded',
],
DOCUMENT_FILENAME_INVALID: [
400,
'Use a simple .pdf filename',
'Supplier document filename rejected',
],
DOCUMENT_FILE_INVALID: [
400,
'Upload a valid PDF file',
'Supplier document MIME or signature rejected',
],
DOCUMENT_DECISION_EXISTS: [
409,
'Document version was already validated',
'Duplicate supplier document validation rejected',
],
DOCUMENT_REJECTION_REASON_REQUIRED: [
400,
'Give a reason for rejecting the document',
'Supplier document rejection lacked reason',
],
DOCUMENT_SELF_VALIDATION_DENIED: [
403,
'Another reviewer must validate this document',
'Supplier document self-validation rejected',
],
DOCUMENT_PENDING_REVIEW: [
403,
'Document is awaiting validation',
'Pending supplier document download rejected',
],
DOCUMENT_REJECTED: [
403,
'Document was rejected',
'Rejected supplier document download rejected',
],
DOCUMENT_INTEGRITY_FAILURE: [
500,
'Document is temporarily unavailable',
'Supplier document checksum verification failed',
],
BOM_NOT_FOUND: [
404,
'Bill of materials not found',
'Scoped BOM lookup failed',
],
BOM_VARIANT_INACTIVE: [
409,
'Variant is inactive',
'BOM variant eligibility failed',
],
BOM_MATERIAL_INACTIVE: [
409,
'A material is inactive',
'BOM material eligibility failed',
],
BOM_MATERIAL_MISSING: [
404,
'A material was not found',
'BOM material scope lookup failed',
],
BOM_REVISION_LIMIT: [
409,
'BOM revision limit reached',
'BOM resource quota exceeded',
],
BOM_NOT_DRAFT: [
409,
'Only a draft BOM can be activated',
'BOM lifecycle transition rejected',
],
BOM_REVISION_STALE: [
409,
'A newer BOM revision is already active',
'BOM activation order rejected',
],
PACKAGING_MATERIAL_KIND: [
409,
'Packaging BOM lines must use packaging or label materials',
'Packaging BOM material kind rejected',
],
BATCH_NOT_FOUND: [
404,
'Production batch not found',
'Scoped production batch lookup failed',
],
BATCH_REFERENCE_CONFLICT: [
409,
'Batch reference is already used',
'Production batch reference duplicate',
],
BATCH_BOM_NOT_ACTIVE: [
409,
'An active BOM is required',
'Production batch BOM eligibility failed',
],
BATCH_BOM_KIND: [
409,
'Production batches require a production BOM',
'Production batch BOM kind rejected',
],
BATCH_VARIANT_INACTIVE: [
409,
'The variant is inactive',
'Production batch variant eligibility failed',
],
BATCH_YIELD_MISMATCH: [
409,
'Planned quantity must be a multiple of BOM yield',
'Production batch yield mismatch',
],
BATCH_MATERIAL_LIMIT: [
409,
'Planned material quantity exceeds the supported limit',
'Production batch material scaling overflow',
],
BATCH_START_STATE: [
409,
'Only a draft batch can start',
'Production batch start transition rejected',
],
BATCH_COMPLETE_STATE: [
409,
'Only a started batch can complete',
'Production batch completion transition rejected',
],
BATCH_CANCEL_STATE: [
409,
'This batch cannot be cancelled',
'Production batch cancellation transition rejected',
],
BATCH_QUANTITY_MISMATCH: [
409,
'Good and rejected quantities must equal the plan',
'Production batch completion reconciliation failed',
],
BATCH_REJECTION_REASON_REQUIRED: [
400,
'Give a reason for rejected pieces',
'Production batch completion rejection lacked reason',
],
USAGE_LINE_NOT_FOUND: [
404,
'BOM material line not found for this batch',
'Production material line scope lookup failed',
],
USAGE_BATCH_STATE: [
409,
'Material usage requires a started batch',
'Production material usage state rejected',
],
USAGE_WASTE_REASON_REQUIRED: [
400,
'Give a reason for wasted material',
'Production material wastage lacked reason',
],
USAGE_EVENT_LIMIT: [
409,
'Material usage event limit reached',
'Production material usage resource quota exceeded',
],
USAGE_REPLAY_CONFLICT: [
409,
'Idempotency key was used for different material usage',
'Production material usage idempotency payload mismatch',
],
PACKAGING_RUN_NOT_FOUND: [
404,
'Packaging record not found',
'Packaging run scoped lookup failed',
],
PACKAGING_BATCH_STATE: [
409,
'Packaging requires a completed batch',
'Packaging batch state rejected',
],
PACKAGING_BOM_MISMATCH: [
409,
'Packaging BOM must be active for this variant',
'Packaging BOM eligibility failed',
],
PACKAGING_YIELD_MISMATCH: [
409,
'Good quantity must be a multiple of packaging BOM yield',
'Packaging yield mismatch',
],
PACKAGING_LINES_MISMATCH: [
400,
'Provide every packaging BOM line exactly once',
'Packaging line reconciliation failed',
],
PACKAGING_WASTE_REASON_REQUIRED: [
400,
'Give a reason for wasted packaging',
'Packaging waste reason missing',
],
PACKAGING_ALREADY_RECORDED: [
409,
'Packaging is already recorded for this batch',
'Packaging batch duplicate rejected',
],
PACKAGING_REPLAY_CONFLICT: [
409,
'Idempotency key was used for different packaging',
'Packaging idempotency payload mismatch',
],
COST_RATE_MISSING: [
409,
'Set a material cost rate for every BOM line in this currency',
'BOM cost estimate missing material rate',
],
COST_RATE_LIMIT: [
409,
'Material cost rate revision limit reached',
'Material cost rate revision quota exceeded',
],
COST_AMOUNT_LIMIT: [
409,
'Cost estimate exceeds the supported amount',
'BOM cost arithmetic overflow',
],
COST_MATERIAL_INACTIVE: [
409,
'Activate the material before setting its cost',
'Inactive material cost rate rejected',
],
BATCH_COST_NOT_FOUND: [
404,
'Batch cost snapshot not found',
'Batch cost scoped lookup failed',
],
BATCH_COST_STATE: [
409,
'Complete the batch before costing it',
'Batch cost state rejected',
],
BATCH_COST_USAGE_INCOMPLETE: [
409,
'Record usage for every production BOM line before costing',
'Batch cost production usage incomplete',
],
BATCH_COST_PACKAGING_MISSING: [
409,
'Record packaging before costing this batch',
'Batch cost packaging record missing',
],
BATCH_COST_QUANTITY_LIMIT: [
409,
'Actual material quantity exceeds the supported limit',
'Batch cost quantity aggregation overflow',
],
BATCH_COST_ALREADY_RECORDED: [
409,
'This batch already has a cost snapshot',
'Batch cost duplicate rejected',
],
BATCH_COST_REPLAY_CONFLICT: [
409,
'Idempotency key was used for different batch costing',
'Batch cost idempotency payload mismatch',
],
MATERIAL_STOCK_NOT_FOUND: [
404,
'Warehouse material stock item not found',
'Material stock scoped lookup failed',
],
MATERIAL_POSTING_NOT_FOUND: [
404,
'Receipt stock posting not found',
'Material receipt posting scoped lookup failed',
],
MATERIAL_RECEIPT_QC_INCOMPLETE: [
409,
'Inspect every receipt line before posting stock',
'Material receipt stock QC gate failed',
],
MATERIAL_RECEIPT_ALREADY_POSTED: [
409,
'Receipt stock was already posted',
'Material receipt duplicate stock posting rejected',
],
MATERIAL_RECEIPT_REPLAY_CONFLICT: [
409,
'Idempotency key was used for different receipt stock',
'Material receipt stock idempotency payload mismatch',
],
MATERIAL_STOCK_CAPACITY: [
409,
'Warehouse material stock capacity exceeded',
'Material stock balance overflow',
],
PRODUCTION_STOCK_POSTING_NOT_FOUND: [
404,
'Production stock posting not found',
'Production stock posting scoped lookup failed',
],
PRODUCTION_STOCK_BATCH_STATE: [
409,
'Complete the batch before posting material stock',
'Production stock batch state rejected',
],
PRODUCTION_STOCK_USAGE_INCOMPLETE: [
409,
'Record usage for every production BOM line before posting stock',
'Production stock usage reconciliation failed',
],
PRODUCTION_STOCK_INSUFFICIENT: [
409,
'Insufficient material stock in this warehouse',
'Production stock balance check failed',
],
PRODUCTION_STOCK_ALREADY_POSTED: [
409,
'Material stock was already posted for this batch',
'Production stock duplicate posting rejected',
],
PRODUCTION_STOCK_REPLAY_CONFLICT: [
409,
'Idempotency key was used for different production stock',
'Production stock idempotency payload mismatch',
],
PACKAGING_STOCK_POSTING_NOT_FOUND: [
404,
'Packaging stock posting not found',
'Packaging stock posting scoped lookup failed',
],
PACKAGING_STOCK_INSUFFICIENT: [
409,
'Insufficient packaging material stock in this warehouse',
'Packaging stock balance check failed',
],
PACKAGING_STOCK_ALREADY_POSTED: [
409,
'Packaging stock was already posted for this batch',
'Packaging stock duplicate posting rejected',
],
PACKAGING_STOCK_REPLAY_CONFLICT: [
409,
'Idempotency key was used for different packaging stock',
'Packaging stock idempotency payload mismatch',
],
FINISHED_GOODS_RECEIPT_NOT_FOUND: [
404,
'Finished-goods receipt not found',
'Finished-goods receipt scoped lookup failed',
],
FINISHED_GOODS_REPLAY_CONFLICT: [
409,
'Idempotency key was used for different finished goods',
'Finished-goods receipt idempotency payload mismatch',
],
FINISHED_GOODS_ALREADY_POSTED: [
409,
'Finished goods were already received for this batch',
'Finished-goods duplicate receipt rejected',
],
FINISHED_GOODS_BATCH_STATE: [
409,
'Complete the batch before receiving finished goods',
'Finished-goods batch state rejected',
],
FINISHED_GOODS_NO_OUTPUT: [
409,
'This batch has no good finished goods to receive',
'Finished-goods zero output rejected',
],
FINISHED_GOODS_PACKAGING_REQUIRED: [
409,
'Record packaging before receiving finished goods',
'Finished-goods packaging record missing',
],
FINISHED_GOODS_PRODUCTION_STOCK_REQUIRED: [
409,
'Post production material stock before receiving finished goods',
'Finished-goods production stock gate failed',
],
FINISHED_GOODS_PACKAGING_STOCK_REQUIRED: [
409,
'Post packaging material stock before receiving finished goods',
'Finished-goods packaging stock gate failed',
],
FINISHED_GOODS_STOCK_CAPACITY: [
409,
'Finished-goods warehouse stock capacity exceeded',
'Finished-goods stock integer bound exceeded',
],
FINISHED_GOODS_KEY_CONFLICT: [
409,
'Idempotency key is already used for another stock entry',
'Finished-goods stock ledger idempotency key conflict',
],
MATERIAL_TRANSFER_NOT_FOUND: [
404,
'Material transfer not found',
'Material transfer scoped lookup failed',
],
MATERIAL_TRANSFER_REPLAY_CONFLICT: [
409,
'Idempotency key was used for a different material transfer',
'Material transfer idempotency payload mismatch',
],
MATERIAL_TRANSFER_SAME_WAREHOUSE: [
400,
'Choose different source and destination warehouses',
'Material transfer identical warehouses rejected',
],
MATERIAL_TRANSFER_SOURCE_WAREHOUSE_NOT_FOUND: [
404,
'Source warehouse not found',
'Material transfer source warehouse scoped lookup failed',
],
MATERIAL_TRANSFER_DESTINATION_WAREHOUSE_NOT_FOUND: [
404,
'Destination warehouse not found',
'Material transfer destination warehouse scoped lookup failed',
],
MATERIAL_TRANSFER_SOURCE_STOCK_NOT_FOUND: [
404,
'Material has no stock in the source warehouse',
'Material transfer source stock scoped lookup failed',
],
MATERIAL_TRANSFER_INSUFFICIENT: [
409,
'Insufficient material in the source warehouse',
'Material transfer source balance check failed',
],
MATERIAL_TRANSFER_DESTINATION_CAPACITY: [
409,
'Destination material stock capacity exceeded',
'Material transfer destination balance overflow',
],
MATERIAL_ADJUSTMENT_NOT_FOUND: [
404,
'Material stock adjustment not found',
'Material adjustment scoped lookup failed',
],
MATERIAL_ADJUSTMENT_REPLAY_CONFLICT: [
409,
'Idempotency key was used for a different material adjustment',
'Material adjustment idempotency payload mismatch',
],
MATERIAL_ADJUSTMENT_STOCK_NOT_FOUND: [
404,
'No material stock exists to decrease in this warehouse',
'Material adjustment negative balance target missing',
],
MATERIAL_ADJUSTMENT_INSUFFICIENT: [
409,
'Material adjustment exceeds warehouse stock',
'Material adjustment negative balance rejected',
],
MATERIAL_ADJUSTMENT_CAPACITY: [
409,
'Material adjustment exceeds warehouse stock capacity',
'Material adjustment positive balance overflow',
],
} as const;