{"record":{"id":"76bcb3ee7be55bf1","repo":"medusajs/medusa","slug":"invalid-data-76bcb3","errorCode":"invalid_data","errorMessage":"Cannot complete a cart with no items","messagePattern":"Cannot complete a cart with no items","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/core/core-flows/src/cart/steps/validate-cart-items.ts","lineNumber":41,"sourceCode":"/**\n * This step validates that a cart has at least one line item before\n * completing the cart and placing an order. If the cart has no items,\n * the step throws an error.\n *\n * @example\n * validateCartItemsStep({\n *   cart\n * })\n *\n * @since 2.14.3\n */\nexport const validateCartItemsStep = createStep(\n  validateCartItemsStepId,\n  async (data: ValidateCartItemsStepInput) => {\n    const { cart } = data\n\n    if (!cart.items?.length) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `Cannot complete a cart with no items`\n      )\n    }\n\n    return new StepResponse(void 0)\n  }\n)\n","sourceCodeStart":23,"sourceCodeEnd":50,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/core-flows/src/cart/steps/validate-cart-items.ts#L23-L50","documentation":"The store gift-card route queries the loyalty module by code (or id); when no gift card matches, it returns MedusaError NOT_FOUND 'Gift card not found'. This is the standard 404 path for unknown/invalid codes.","triggerScenarios":"GET /store/gift-cards/{code} where the code doesn't match any gift card — mistyped code, deleted gift card, or looking up by a code scoped to another channel/store.","commonSituations":"Checkout forms where the customer pastes an invalid/expired code; gift cards created in a different environment; codes with case or whitespace differences.","solutions":["Verify the exact code, trimmed and case-corrected, against the gift card in admin","Catch NOT_FOUND and show a friendly 'invalid code' message to the customer","Ensure the gift card exists and is active in the same store scope before offering it"],"exampleFix":"// before\nconst { gift_card } = await sdk.store.giftCard.retrieve(code)\n// after\ntry { const { gift_card } = await sdk.store.giftCard.retrieve(code) } catch (e) { if (e.type === 'not_found') return showInvalidCodeMessage() throw e }","handlingStrategy":"try-catch","validationCode":"const gift_card = await query.graph({ entity: 'gift_card', filters: { code } }).then(r => r.data[0] ?? null)\nif (!gift_card) return invalidCodeResponse()","typeGuard":null,"tryCatchPattern":"try { const { gift_card } = await sdk.store.giftCard.retrieve(code) } catch (e) { if (e.type === 'not_found') return showInvalidCode(); throw e }","preventionTips":["Trim and normalize customer-entered codes before lookup","Show friendly validation messages for unknown codes instead of raw errors"],"tags":["store-api","gift-card","not-found","http"],"backgroundTag":"resource-not-found","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}