Error Handling

Handle common HTTP status codes:

Error Response Structure

When returning errors, use this structure:

{
  "status": "errored",
  "location_id": "loc-001",
  "request_uid": "order-12345",
  "errors": [
    {
      "error_code": "VALIDATION_FAILED",
      "error": "Item 'XYZ' not found in menu",
      "timestamp": "2025-01-15T10:30:00Z"
    },
    {
      "error_code": "INVALID_PRICE",
      "error": "Price mismatch for item 'ABC'",
      "timestamp": "2025-01-15T10:30:00Z"
    }
  ]
}

HTTP Status Codes

HTTP Code Error When To Use
200 OK Successful operation
202 Accepted Accepted for async processing
400 Bad Request Invalid request format or validation failed
401 Unauthorized Authentication failed (invalid JWT or signature)
404 Not Found Resource not found (order, location, menu)
500 Internal Server Error Server error (use sparingly, prefer specific error codes)

Common Error Codes

Error Code Description
VALIDATION_FAILED Order validation failed
INVALID_LOCATION Location not found or inactive
UNAUTHORIZED Authentication failed
INVALID_SIGNATURE Payload signature validation failed
ITEM_NOT_FOUND Menu item not found
PRICE_MISMATCH Price doesn't match menu
INVENTORY_UNAVAILABLE Item out of stock
LOCATION_CLOSED Location not accepting orders