Skip to content

[Bug]: JS SDK drops code and type from API error responses #16770

Description

@robindelaater

This was generated by AI during triage.

Description

@medusajs/js-sdk parses Store and Admin API error responses, but normalizeResponse only forwards the response's message to FetchError. The API's stable code and type fields are discarded.

This forces SDK consumers to distinguish failures by matching human-readable English messages. That is brittle when messages change and prevents storefronts from reliably mapping errors to localized copy. A common example is handling insufficient_inventory during add-to-cart or line-item quantity updates.

Reproduction

  1. Use the JS SDK to make a request that returns a Medusa error body with code, type, and message, for example an inventory request above the available quantity:
{
  "code": "insufficient_inventory",
  "type": "invalid_data",
  "message": "Some variant does not have the required inventory"
}
  1. Catch and inspect the resulting FetchError:
try {
  await sdk.store.cart.updateLineItem(cartId, itemId, { quantity: 999 })
} catch (error) {
  console.log(error.status) // 400
  console.log(error.message) // preserved
  console.log(error.code) // undefined
  console.log(error.type) // undefined
}

This behavior is present in @medusajs/js-sdk versions 2.0.0 through 2.20.1.

Expected behavior

FetchError should preserve the API response's code and type fields so consumers can handle errors using stable identifiers.

Actual behavior

Only status and message are exposed; code and type are lost in normalizeResponse.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions