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
- 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"
}
- 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.
Description
@medusajs/js-sdkparses Store and Admin API error responses, butnormalizeResponseonly forwards the response'smessagetoFetchError. The API's stablecodeandtypefields 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_inventoryduring add-to-cart or line-item quantity updates.Reproduction
code,type, andmessage, for example an inventory request above the available quantity:{ "code": "insufficient_inventory", "type": "invalid_data", "message": "Some variant does not have the required inventory" }FetchError:This behavior is present in
@medusajs/js-sdkversions 2.0.0 through 2.20.1.Expected behavior
FetchErrorshould preserve the API response'scodeandtypefields so consumers can handle errors using stable identifiers.Actual behavior
Only
statusandmessageare exposed;codeandtypeare lost innormalizeResponse.