# Responses & Errors

> This page explains how the Vitrin (window\.zid) handles success and error responses across all modules.

---

## Success Responses

### Direct Data Response

Most API calls return the data directly:

```js
const cart = await zid.cart.get();
console.log(cart.products);
```

```js
const result = await zid.cart.addProduct({ product_id: '123', quantity: 2 });
console.log(result.item);
console.log(result.cart_items_quantity);
```

---

## Error Responses

### Error Types

* **API Errors**

  * `error.status` → HTTP status code
  * `error.responseData` → Full error body

### Error Handling Examples

### Basic Handling

```js
try {
  const cart = await zid.cart.get();
} catch (error) {
  console.log(error.status, error.responseData);
}

// Or using then/catch
zid.cart.get()
  .then(cart => {
    console.log(cart.products);
  })
  .catch(error => {
    console.log(error.status, error.responseData);
  });
```

### Different Error Types

```js
try {
  await zid.cart.addProduct({ product_id: '123', quantity: 1 });
} catch (error) {
   // handle your error logic here
}
```

### Common HTTP Status Codes

| Code | Meaning          |
| ---- | ---------------- |
| 200  | Success          |
| 201  | Created          |
| 400  | Bad Request      |
| 401  | Unauthorized     |
| 403  | Forbidden        |
| 404  | Not Found        |
| 422  | Validation Error |
| 500  | Server Error     |

---


