# Error Codes

全 ingestion API 共通。`shop` はボディ、認証は `x-ingest-secret` ヘッダーです。

## HTTP ステータス

| Status | 条件                                | レスポンス例                                                                                                                                                               |
| :----: | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|  `400` | ボディ形式エラー                          | `{ "ok": false, "error": "shop required" }` / `"products[] required and non-empty"` / `"rows[] required and non-empty"` / `"mode must be \"absolute\" or \"delta\""` |
|  `401` | `x-ingest-secret` 不一致             | `unauthorized`                                                                                                                                                       |
|  `405` | POST 以外のメソッド                      | `method_not_allowed`                                                                                                                                                 |
|  `422` | 解決失敗等（`ok:false`、`error_kind` 付き） | `{ "ok": false, "error_kind": "location_unresolved", "error": "no location for ..." }`                                                                               |
|  `500` | サーバー内部エラー                         | `{ "ok": false, "error": "..." }`                                                                                                                                    |
|  `503` | `INGEST_SECRET` 未設定               | `{ "ok": false, "error": "INGEST_SECRET not configured" }`                                                                                                           |

`error_kind`（422）: `invalid_payload` / `location_unresolved` / `location_ambiguous`。

## レスポンスボディ内の行単位エラー

HTTP `200` でも、行単位の不備はレスポンス内の配列で返り、正常行の処理は継続します（silent skip しません）。

| API                            | 配列             | code / reason                                                                                                           | 説明                            |
| ------------------------------ | -------------- | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
| Products                       | `errors[]`     | `barcode and product_name required`                                                                                     | 必須欠落（該当行 skip）                |
| Inventory Snapshot / Available | `unresolved[]` | `product_not_found` / `missing_barcode` / `missing_on_hand_qty`                                                         | barcode 未登録・必須欠落（該当行 skip）    |
| Inventory Available (delta)    | `clamped[]`    | —                                                                                                                       | `available_qty` が負になり 0 にクランプ |
| Order Line Master              | `errors[]`     | `required` / `location_not_found` / `channel_not_found` / `amount_inconsistency` / `out_of_range` / `invalid_timestamp` | 当該行を reject                   |
| Order Line Master              | `warnings[]`   | `product_not_in_master_warning`                                                                                         | barcode 未登録だが投入（要マスター登録）      |

## Routing — `/api/routing/orders` の差分

* バリデーション失敗は `error_kind`（422）ではなく **`400` + `invalid_input`** を返します: `{ "ok": false, "error": "invalid_input", "details": [{ "path": "lines.0.quantity", "message": "..." }] }`
* JSON パース失敗は `400` `{ "ok": false, "error": "invalid json body" }`
* 引き当て不能の明細は `shippingInstruction.unroutableLines[]`（`reason`）に返り、HTTP は `200` です（全 unit 不能のときは `status: no_stock`）。
* 外部 dispatch 失敗は HTTP `200` のまま `ok: false` / `status: failed`（ルーティング自体は成功・保存済）。
* 出荷元の解決失敗は `422` + `error_kind`: `fulfillment_source_unresolved`（shop 内に出荷元 location 無し）/ `fulfillment_source_no_members`（出荷元に有効メンバー無し）。
* `/api/routing/reallocate` で routing order が存在しないときは `404` + `error_kind: not_found`。


---

# Agent Instructions: 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:

```
GET https://lmile.gitbook.io/lmile-docs/reference/error-codes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
