🚨Error Responses

πŸ’‘ Comprehensive guide to error responses, validation, and troubleshooting


πŸ“Š Error Response Structure

All error responses follow a consistent envelope structure:

{
  "success": false,
  "message": "Human-readable error description",
  "data": {}
}

🏷️ Error Code Categories

HTTP Status Codes

Status Code
Category
Description

400

Bad Request

Invalid request data, missing required fields, or validation errors

404

Not Found

Resource not found (tenant, customer, product, order)

500

Internal Server Error

Server-side errors, storage failures, or unexpected exceptions


❌ Common Error Scenarios

1. Missing Required Fields (400)

What happened: Your request is missing required information

Response example:

Suggested actions:

  • Review the errors object to identify missing fields

  • Ensure all required fields are included in your request

  • Check field names match exactly (case-sensitive)

2. Field Length Exceeded (400)

What happened: One or more fields exceed the maximum allowed length

Response example:

Suggested actions:

  • Truncate field values to respect maximum lengths

  • Implement client-side validation before sending requests

  • Review field length limits in API documentation

3. Tenant Not Found (404)

What happened: The tenant ID you provided does not exist in our system

Response example:

Status code: 404 Not Found

Suggested actions:

  • Verify the tenant ID is correct (must be a valid GUID)

  • Ensure tenant is properly configured in the system

  • Check that you're using the correct environment (dev/staging/production)

  • Contact support if tenant should exist

4. Resource Not Found (404)

What happened: The resource you're trying to delete does not exist

Response examples:

Suggested actions:

  • Verify the resource ID exists

  • Check if resource was already deleted

  • Ensure using correct identifier format

5. Storage/Delete Failure (500)

When it occurs: An error occurred while deleting a resource from storage

Response examples:

Suggested actions:

  • Retry the request with exponential backoff

  • Check system status for outages

  • Contact support if errors persist

  • Implement circuit breaker pattern for resilience

6. Internal Server Error (500)

When it occurs: An unexpected error occurred while processing your request

Response example:

Suggested actions:

  • Retry the request with exponential backoff

  • Check system status for outages

  • Contact support if errors persist

  • Implement circuit breaker pattern for resilience

6. Invalid Request Format (400)

What happened: Your request body is not properly formatted

Response example:

Suggested actions:

  • Validate JSON syntax

  • Ensure Content-Type header is application/json

  • Check for proper array wrapping (endpoints expect arrays)


βœ… How Request Validation Works

We automatically validate your API requests to ensure data quality and prevent errors.

What We Check

Required Information

  • All mandatory fields are present in your request

  • At least one identifier is provided (e.g., Email or CustomerId)

Data Integrity

  • Field values match expected data types (strings, numbers, booleans)

  • Text fields don't exceed maximum lengths

  • Dates are in valid ISO-8601 format

Business Rules

  • Currency codes follow ISO 4217 standard

  • Language tags follow IETF BCP 47 standard

  • Email addresses are properly formatted

When Validation Fails

If your request doesn't meet these requirements, you'll immediately receive a 400 Bad Request response with:

  • Specific field names that need correction

  • Clear description of what's wrong

  • Suggested fixes

Example validation error:

Best Practice

Validate data on your side before sending to avoid round-trip errors:

  • Check required fields are present

  • Verify string lengths

  • Ensure data types are correct


πŸ” Validation Error Decoder

Quick reference to understand and fix common validation errors.

Understanding Error Field Paths

The errors object uses array notation to show exactly where the problem is:

Error Path
What It Means

[0].ProductId

First product in array is missing ProductId

[0].ProductVariants[0].Sku

First variant of first product is missing Sku

[2].OrderItems[1].Price

Second item in third order is missing Price

CustomerId

Single object (not array) missing CustomerId

Common Validation Errors & Fixes

Error Message
What It Means
How to Fix

"The ProductId field is required."

Missing required ProductId

Add "ProductId": "your-id" to product

"The Currency field is required."

Missing required Currency

Add "Currency": "USD" (or EUR, GBP, etc.)

"The field ProductId must be a string with a maximum length of 100."

ProductId too long

Shorten ID to 100 characters or less

"The field Currency must be a string with a maximum length of 3."

Currency too long

Use 3-letter ISO code: USD, EUR, GBP

"The Language field is required."

Missing required Language

Add "Language": "en-US" (IETF BCP 47 format)

"The GdprOptin field is required."

Missing required GdprOptin

Add "GdprOptin": true or false

Field Requirements by Endpoint

Products API

Required:

  • ProductId (string, max 100 chars)

  • ProductVariants (array, can be empty [])

Per Variant (if variants exist):

  • VariantId (string, max 100 chars)

  • Sku (string, max 50 chars)

Customers API

Required (depends on tenant config):

  • Either CustomerId OR Email (at least one)

  • Sometimes Language (check tenant settings)

  • Sometimes GdprOptin (check tenant settings)

Orders API

Required:

  • OrderId (string, max 100 chars)

  • Currency (string, max 3 chars, use 3-letter code)

Per Order Item:

  • ProductId (string, max 100 chars)

  • Sku (string, max 50 chars)

  • Quantity (integer)

  • Price (number)

Quick Fixes Checklist

Before making your API request:


πŸ’‘ Best Practices for Error Handling

Client-Side Implementation

Validation Before Submission


βœ… Pre-Flight Validation

Catch errors BEFORE making API calls:

Customer Validation Script

Order Validation Script


1. Check Request Headers

2. Validate JSON Structure

3. Enable Detailed Logging

  • Check traceId in error responses

  • Correlate with server logs using trace ID

  • Monitor response times for timeout issues

4. Common Pitfalls

Issue
Solution

Missing array wrapper

Request body must be an array: [{...}] not {...}

Case sensitivity

Field names are case-sensitive: use CustomerId not customerid

Null handling

Use null for empty values, not undefined

Date format

Use ISO-8601: 2024-12-22T10:30:00Z

Boolean values

Use true/false, not strings "true"/"false"

Currency format

Use ISO 4217 codes: USD not $ or usd

Language format

Use IETF tags: en-US not English


πŸ“ž When to Contact Support

Reach out to our support team if you experience:

Persistent Issues

  • 500 errors that continue after multiple retry attempts

  • Consistent timeout errors with small payloads

  • Rate limiting issues despite following best practices

Unexpected Behavior

  • 404 errors for resources you know exist

  • Authentication failures with valid credentials

  • Error messages that don't match this documentation

When contacting support, please provide:

  • Your tenant ID

  • Timestamp when the issue occurred (in UTC)

  • Full error response (sanitized to remove sensitive data)

  • Request payload example (sanitized)

  • Expected vs actual behavior

Contact: support@replen.itenvelope


Last updated