merce.STACK
merce.STACK
Skip to content
PricingWhat's new
Log inGet started
{}Developers
GuidesAPI referenceChangelogGet API keys →
  • Get started

    • Quickstart
    • Keys & authentication
  • Storefront

    • Products & catalog
    • Carts
    • Checkout & payment
    • Customer accounts
    • Digital products
    • Without a build step
    • Bookings
    • Courses
    • Drop-in components
  • Server API

    • Server API
    • Customers
    • Payment links & transactions
    • Balance & payouts
    • Classes & students
    • Node SDK
  • Email API

    • Email API
    • Sending email
    • Delivery events
  • Events & errors

    • Webhooks
    • Errors
  • Reference

    • API reference
    • Changelog

Events & errors

Errors

One error type, stable codes. Branch on the code, never the text.

TypeScript
import { MercestackError } from "@mercestack/commerce";

try {
  await mercestack.addToCart({ variantId });
} catch (error) {
  if (error instanceof MercestackError) {
    error.code;         // "OUT_OF_STOCK"
    error.status;       // 400
    error.requestId;    // quote this to support
    error.isRetryable;  // network, rate limit, 5xx
    error.details;      // anything else the API sent
  }
}

Messages are written for humans and get rewritten. A client that does if (message.includes("out of stock")) breaks the day somebody improves the wording — branch on code.

CodeWhat happened
OUT_OF_STOCKNot enough available, and backorders are off
PRODUCT_NOT_AVAILABLEUnpublished or archived since it was added
INVALID_VARIANTNo such variant in this store
PRICE_CHANGEDThe price moved between display and checkout
CART_EXPIREDUntouched too long. The SDK recovers from this for you
CART_EMPTYNothing to check out
DISCOUNT_INVALIDExpired, exhausted, or never existed
GIFT_CARD_INVALIDWrong code, cancelled, expired, or empty
PAYMENT_FAILEDThe provider declined it
UNAUTHORIZEDMissing or revoked key
FORBIDDENKey exists but is not allowed to do this
RATE_LIMITEDToo many requests. Back off and retry

Every response carries a Mercestack-Request-Id header, and it matches a line in Commerce → Developers → API logs. It is the fastest way to have someone find out what actually happened.

The SDK retries transient failures — network errors, rate limits, 5xx — with exponential backoff. It does not retry a 400: that is the same wrong request sent again.

← PreviousWebhooksNext →API reference
Create a workspaceTalk to usPricing

One workspace for everything your business runs on — your team, customers, store, marketing and payouts in one place.

Get started

Product

  • All products
  • Pricing
  • What's new
  • Security

Resources

  • Documentation
  • Guides
  • Use cases
  • Blog
  • Get support

Company

  • About
  • Careers
  • Contact us
  • Talk to the team

Legal

  • Privacy
  • Terms
  • Cookie policy
  • GDPR
  • Report a vulnerability

© 2026 Mercestack. All rights reserved.

Mercestack StructureOS

mercestack