# Responses

## Success Status Codes

The following HTTP status codes are used for successful requests.

| Status Code | Description | Reason |
| --- | --- | --- |
| `200` | Success | Successfully completed request |
| `201` | Created | The entity was successfully created |
| `204` | No Content | Successfully completed request with an empty body |
| `228` | Created with issues | The entity was created, but has issues that may need to be addressed |

## Error Status Codes

If there are any errors with the request, an error status code will be returned along 
with further details of the error in the response body as an array of JSON error objects.

| Status Code | Description | Reason |
| --- | --- | --- |
| `400` | Bad Request | Request is invalid |
| `401` | Unauthorized | Access token or credentials are not valid |
| `403` | Forbidden | No permissions to access the resource |
| `404` | Not Found | The resource does not exist, is an invalid URL or unknown version |
| `405` | Method Not Allowed | Invalid method (GET, POST, PUT, etc.) |
| `406` | Not Acceptable | Invalid Accept-Version header provided |
| `409` | Conflict | Operation cannot be performed as the resource has been modified by another request |
| `412` | Precondition Failed | Server does not meet one of the preconditions provided in the request header fields |
| `422` | Unprocessable Entity | Structure of the request is valid, but data content is invalid or not compatible with the request |
| `429` | Too Many Requests | Rate limiting has been applied |
| `500` | Internal Server Error | An issue with our server. Try again later. |
| `503` | Service Unavailable | Temporarily offline for maintenance. Try again later. |

## Error Response Data

### General

> Example Response JSON

```json
[
  {
    "message": "Request method 'PUT' not supported"
  }
]
```

Some errors will simply return a text description of the error encountered, but will still follow the same data structure.

| Property | Description |
| --- | --- |
| `message` | A description of the error |


Error codes issued in payload responses:

| Code  | Description                                       |
|-------|---------------------------------------------------|
| 10100 | Consignment not found                             |
| 10200 | Multiple consignments found                       |
| 10201 | Consignment is group child                        |
| 10202 | Consignment not approved                          |
| 10203 | Unable to allocate consignment                    |
| 10204 | Consignment not allocated to run                  |
| 10205 | Unable to update to In Warehouse                  |
| 10206 | Driver not found                                  |
| 10207 | Consignment not allocated to Run and no Run given |
| 10208 | Delivery Run not found                            |
| 10209 | Unable to create Run Sheet                        |
| 10210 | Run Sheet not found                               |
| 10211 | Invalid request                                   |
| 10212 | Consignment already allocated                     |
| 10213 | Cannot allocate Consignment                       |
| 10214 | Consignment already In Warehouse                  |
| 10300 | Storage Period cannot be created                  |
| 10301 | Storage Period duplicate                          |
| 10400 | Sale Order not found                              |
| 10401 | Sale Order not Packing In Progress                |
| 10402 | Sale Order Rejected                               |
| 10403 | Sale Order import error duplicate                 |
| 10404 | Sale Order import error wrong Warehouse           |
| 10405 | Sale Order import error unauthorized Warehouse    |
| 10406 | Sale Order import error Customer does not exist   |
| 10443 | Product error                                     |
| 10444 | Product error expired                             |
| 10445 | Product error expiry threshold                    |
| 10446 | Product error warning threshold                   |
| 10447 | Product error out of stock                        |
| 10448 | Product error not enough stock                    |
| 10449 | Product error Product not found                   |
| 10450 | Product error Product deactivated                 |
| 10451 | Product error Product qty is not number           |
| 10452 | Product error Product qty is negative             |
| 10453 | Product error Product qty is zero                 |
| 10454 | Product error Product conversion failed           |
| 10455 | Product error invalid Unit Of Measure             |
| 10456 | Product error unable to parse                     |
| 10457 | Product error too many products found             |
| 10458 | Product error qty not whole                       |
| 10459 | Product error product code not specified          |
| 11000 | Customer not found                                |
| 12000 | Purchase Order potentially undercharged storage   |

### Validation

A request data validation error will return the error code 422 and the following response 

> Example Response JSON

```json
[
  {
    "field": "/name",
    "message": "Name cannot be empty."
  },
  {
    "field": "/description",
    "message": "Description cannot be empty."
  }
]
```

```json
[
  {
    "field": "/references/customer",
    "message": "A Purchase Order with this Customer Reference already exists.",
    "type": "DUPLICATE",
    "details": {
      "duplicateId": "cd639009-1111-4a89-bf83-8907b8c9d09a"
    }
  }
]
```

An array of validation errors with the fields for which the error applies will be returned.

| Property           | Description                                                                                              |
|--------------------|----------------------------------------------------------------------------------------------------------|
| field              | The property field for which the error applies as a [JSON Pointer](https://tools.ietf.org/html/rfc6901) |
| message            | A description of the validation error                                                                    |
| type (optional)    | The specific type of error                                                                               |
| details (optional) | An array containing errors with extra info                                                               |

### Validation Error Type

| Type      | Properties of Details | Description                         |
|-----------|-----------------------|-------------------------------------|
| DUPLICATE | duplicateId           | The id of duplicate existing record |
