> For the complete documentation index, see [llms.txt](https://developer.esw.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.esw.com/order-api/order-api/error-handling/response-schemas-and-status-codes.md).

# Response schemas and status codes

## Response Schema

### Schema 1&#x20;

Used for: `401`, `403`, `404`, and the `default` response on all endpoints.

```json
{
  "type": "string | null",
  "title": "string | null",
  "status": 400,
  "detail": "string | null",
  "instance": "string | null"
}
```

### Schema 2

Used for `400` on: `GET /Order/{brandOrderReference}`, `GET /Order/{brandOrderReference}/Transaction/{transactionReference}`, `POST /Comment`, and `POST /Replacement`.

```json
{
  "code": 1,
  "message": "Invalid BrandOrderReference"
}
```

### Schema 3&#x20;

Used for `400` on: `POST /Order`, `PUT /ContactDetails`, `POST /OrderActivity`, `POST /LineItemActivity`, `POST /LineItem`, `PATCH /LineItem`, `POST /Appeasement`, `POST /LineItemAppeasement`, `POST /Allocation`.

```json
[
  "Validation error message 1",
  "Validation error message 2"
]
```

***

## HTTP Status Code Reference

<table data-full-width="true"><thead><tr><th>Code</th><th>Meaning</th><th>Body Schema</th><th align="center">Recoverable?</th><th>Notes</th></tr></thead><tbody><tr><td><code>200</code></td><td>OK</td><td>Varies by endpoint</td><td align="center">N/A</td><td>GET operations, Comment, UpdateApproval</td></tr><tr><td><code>202</code></td><td>Accepted (async)</td><td><code>OrderTransactionApiResponse</code></td><td align="center">N/A</td><td>Most write operations — see Section 9</td></tr><tr><td><code>400</code></td><td>Bad Request</td><td><code>Error</code>, <code>string[]</code>, or <code>ProblemDetails</code> — varies</td><td align="center">✅ Yes</td><td>Fix payload before retrying</td></tr><tr><td><code>401</code></td><td>Unauthorized</td><td><code>ProblemDetails</code></td><td align="center">✅ Yes</td><td>Refresh token and retry once</td></tr><tr><td><code>403</code></td><td>Forbidden</td><td><code>ProblemDetails</code></td><td align="center">⚠️ No</td><td>Permissions issue — escalate</td></tr><tr><td><code>404</code></td><td>Not Found</td><td><code>ProblemDetails</code></td><td align="center">✅ Partial</td><td>Verify path parameters</td></tr><tr><td><code>500</code></td><td>Internal Server Error</td><td><strong>None</strong></td><td align="center">⚠️ Maybe</td><td>No body — use exponential backoff</td></tr><tr><td><code>default</code></td><td>Unexpected error</td><td><code>ProblemDetails</code></td><td align="center">⚠️ Varies</td><td>Catch-all — see Section 3</td></tr></tbody></table>

### Status Code Exposure Per Endpoint

<table data-header-hidden data-full-width="true"><thead><tr><th width="375"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th></tr></thead><tbody><tr><td>Endpoint</td><td align="center"><code>200</code></td><td align="center"><code>202</code></td><td align="center"><code>400</code></td><td align="center"><code>401</code></td><td align="center"><code>403</code></td><td align="center"><code>404</code></td><td align="center"><code>500</code></td><td align="center"><code>default</code></td></tr><tr><td><code>POST /{tenantCode}/Order</code></td><td align="center"></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>GET /{tenantCode}/Order/{ref}</code></td><td align="center">✅</td><td align="center"></td><td align="center">✅</td><td align="center"></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>GET /{tenantCode}/Order/{ref}/Transaction/{tRef}</code></td><td align="center">✅</td><td align="center"></td><td align="center">✅</td><td align="center"></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>PUT /{tenantCode}/Order/{ref}/ContactDetails</code></td><td align="center"></td><td align="center">✅</td><td align="center">✅</td><td align="center"></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>POST /{tenantCode}/Order/{ref}/OrderActivity</code></td><td align="center"></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>POST /{tenantCode}/Order/{ref}/LineItemActivity</code></td><td align="center"></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>POST /{tenantCode}/Order/{ref}/LineItem</code></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>PATCH /{tenantCode}/Order/{ref}/LineItem</code></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>POST /{tenantCode}/Order/{ref}/Appeasement</code></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>POST /{tenantCode}/Order/{ref}/LineItemAppeasement</code></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>POST /{tenantCode}/Order/{ref}/Replacement</code></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>POST /{tenantCode}/Order/{ref}/Allocation</code></td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td><td align="center">✅</td></tr><tr><td><code>POST /{tenantCode}/Order/{ref}/Comment</code></td><td align="center">✅</td><td align="center"></td><td align="center">✅</td><td align="center"></td><td align="center">✅</td><td align="center"></td><td align="center">✅</td><td align="center">✅</td></tr></tbody></table>

***

## The `default` Response&#x20;

This is the catch-all for any HTTP status code not explicitly listed — including `422 Unprocessable Entity`, `429 Too Many Requests`, `503 Service Unavailable`, or upstream gateway errors.

Treat `default` as a real code path in every error handler.

{% code expandable="true" %}

```javascript
async function handleOrderApiResponse(response, endpoint) {
  const knownCodes = [200, 202, 400, 401, 403, 404, 500];

  if (!knownCodes.includes(response.status)) {
    // This is a `default` response — parse as ProblemDetails
    const err = await parseOrderApiError(response);
    console.error(`Unexpected status ${response.status} on ${endpoint}:`, err);
    throw new UnexpectedApiError(response.status, err);
  }

  // Handle known codes below...
}
```

{% endcode %}

## Authentication & Authorization Errors

### 401 Unauthorized

`401` uses the `ProblemDetails` schema. It is documented on most — but not all — write endpoints.

| Cause                          | Fix                                                  |
| ------------------------------ | ---------------------------------------------------- |
| Missing `Authorization` header | Add `Authorization: Bearer <token>` to every request |
| Expired JWT                    | Refresh the token and retry once                     |
| Malformed or invalid token     | Re-authenticate to obtain a valid token              |

{% code expandable="true" %}

```javascript
async function callWithRefresh(url, options, getToken, refreshToken, maxAttempts = 2) {
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
    const token = await getToken();
    const response = await fetch(url, {
      ...options,
      headers: { ...options.headers, Authorization: `Bearer ${token}` },
    });

    if (response.status !== 401) return response;

    if (attempt < maxAttempts - 1) {
      console.warn(`401 on attempt ${attempt + 1} — refreshing token.`);
      await refreshToken();
    }
  }
  throw new AuthError("Authentication failed after token refresh.");
}
```

{% endcode %}

### 403 Forbidden

`403` uses `ProblemDetails` and is documented on **every** endpoint.

| Cause                                                  | Fix                                                   |
| ------------------------------------------------------ | ----------------------------------------------------- |
| Token lacks required scope                             | Contact <apisupport@eshopworld.com>                   |
| `tenantCode` in path does not match the token's tenant | Confirm tenantCode matches the authenticated identity |
| Feature not enabled for the tenant                     | Verify feature activation with ESW                    |

`403` is not resolved by refreshing the token. Do not auto-retry — escalate to ESW support.

***

## 400 Bad Request

The `400` body schema varies across endpoints. Applying the wrong parser will fail silently or throw a runtime error.

### 400 Schema Mapping

| Endpoint                              | 400 Schema       |
| ------------------------------------- | ---------------- |
| `GET /Order/{brandOrderReference}`    | `Error` object   |
| `GET /Order/{ref}/Transaction/{tRef}` | `Error` object   |
| `POST /Comment`                       | `Error` object   |
| `POST /Replacement`                   | `Error` object   |
| `POST /Order`                         | `string[]` array |
| `PUT /ContactDetails`                 | `string[]` array |
| `POST /OrderActivity`                 | `string[]` array |
| `POST /LineItemActivity`              | `string[]` array |
| `POST /LineItem`                      | `string[]` array |
| `PATCH /LineItem`                     | `string[]` array |
| `POST /Appeasement`                   | `string[]` array |
| `POST /LineItemAppeasement`           | `string[]` array |
| `POST /Allocation`                    | `string[]` array |

### Schema-Aware 400 Handler

{% code expandable="true" %}

```javascript
async function handle400(response, endpoint) {
  const err = await parseOrderApiError(response);

  switch (err.schema) {
    case "validationArray":
      console.error(`[400] Validation errors on ${endpoint}:`);
      err.errors.forEach((msg, i) => console.error(`  [${i}] ${msg}`));
      throw new ValidationError(endpoint, err.errors);

    case "Error":
      console.error(`[400] Error on ${endpoint}: [${err.code}] ${err.message}`);
      throw new ApiError(err.code, err.message);

    case "ProblemDetails":
      console.error(`[400] Problem on ${endpoint}: ${err.title} — ${err.detail}`);
      throw new ProblemError(err.title, err.detail, err.instance);

    default:
      throw new Error(`[400] Unparseable error on ${endpoint}: ${err.raw}`);
  }
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.esw.com/order-api/order-api/error-handling/response-schemas-and-status-codes.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
