Product

Product Service

Description

  • Purpose: Initializes the service with a custom error handler from Nuxt's context.
  • Dependency: useNuxtApp() is used to extract $customClientErrorHandler.

Utilities/Functions used

getProductByCode(id: number): Promise<{ data: Product } | any>

  • Description: Fetches a single product detail by its unique product code (id).
  • Concurrency Control: Prevents multiple simultaneous calls using a polling lock (isProductDetailFetching).
  • Error Handling: Logs and rethrows errors with metadata including productId.

getProducts(id: number[], cache = false): Promise<Product[] | any>

  • Description: Retrieves a list of products by their IDs.
  • Concurrency Control: Uses isProductListFetching to prevent simultaneous fetches.
  • Cache Support: Accepts a cache flag to determine whether to cache the response.
  • Error Handling: Captures and reports errors with detailed metadata.

getStocks(id: number[], branch_id?: string[])

  • Description: Gets stock availability for given product IDs.
  • Branch Filter: Accepts an optional branch_id parameter.
  • Hardcoded Site: Always uses ["WW"] as the default site.
  • Error Handling: Logs error with stock-related metadata.

getDeliveryDetails(id: number, sites?: string)

  • Description: Fetches delivery details for a given product.
  • Site Filter: Accepts an optional sites parameter.
  • Error Handling: Catches and logs errors related to delivery info retrieval.

subscribeProduct(customer_id: string, productCode: string)

  • Description: Subscribes a customer to stock notifications for a product.
  • HTTP Method: POST
  • Error Handling: Logs subscription errors with relevant metadata.

unSubscribeProduct(customer_id: string, product_id: string)

  • Description: Unsubscribes a customer from stock notifications.
  • HTTP Method: DELETE
  • Error Handling: Captures unsubscription failures with metadata.

Global Error Handling

  • Error Logging: All methods use $customClientErrorHandler with different severity levels (low, high, critical) and context-specific metadata.
  • Consistency: All errors are rethrown after handling, allowing upper layers to manage them further.

Copyright © 2026