API Error Code Document Guidelines
Error documentation has two parts: an MDX page (user-facing) and JSON data files (structured error data rendered by the src/components/ErrorCodePage React components). All files live together in docs/03-Integration/5-convenient-checkout-api/4-error-codes/.
- Adding an error to an existing API's error page
- Creating error documentation for a new API
- Creating a reusable common error object
- Documenting split-tender allocation errors
Quick Startβ
| I want to... | Go to |
|---|---|
| Add an error to an existing API | Adding a New Error Code (edit the JSON; it renders automatically) |
| Create an error page for a new API | Creating an MDX Error Code Page |
| Create a reusable error object | Creating Common Error Objects |
| Document split-tender allocation errors | Documenting Allocation Errors |
| Look up fields or categories | JSON Field Definitions, Error Categories |
File Structureβ
docs/03-Integration/5-convenient-checkout-api/4-error-codes/
βββ payment-error-codes.mdx β MDX pages
βββ refund-error-codes.mdx
βββ session-error-codes.mdx
βββ payment-api.json β API-specific JSON
βββ refund-api.json
βββ session-api.json
βββ common/ β Reusable objects
βββ agent-object.json
βββ config-object.json
βββ customer-object.json
βββ payment-allocation-object.json
βββ payment-consent-object.json
βββ payment-details-object.json
βββ payment-object.json
βββ session-consent-object.json
βββ session-payment-object.json
src/components/ErrorCodePage/ β React components (index.js)
There is no src/data/error-codes/ folder; the JSON sits beside the MDX. The MDX imports components from @site/src/components/ErrorCodePage and JSON from relative paths.
Adding a New Error Codeβ
The most common task: add one error to an existing API's JSON.
- Pick the category (see Error Categories) and use the category
nameexactly as it appears in that API's JSON file. - Open
{api-name}-api.jsonand add the error object to that category'serrorsarray:
{
"id": "payment-amount-required",
"title": "INVALID_REQUEST",
"httpStatus": "400",
"message": "amount is required",
"scenario": ["When amount field is missing in the payment request"],
"resolution": "Include the amount field with a positive integer value.",
"scopeWithEndPoint": [
{ "merchant": ["POST /v2/payments"] }
],
"sampleResponse": {
"title": "INVALID_REQUEST",
"status": 400,
"detail": "amount is required"
},
"description": "Error returned when amount is missing."
}
- Verify. Run
yarn startand open the error code page. The error renders when the category name matches exactly (case-sensitive), the JSON is valid, and the required fields are present.
Creating an MDX Error Code Pageβ
Create {api-name}-error-codes.mdx in the same folder. Use the categories that exist in your JSON file, in the standard order. Copy the heading text and category strings from the API's JSON (the example below uses the Payment API names).
---
sidebar_position: 2
slug: /integration/convenient-checkout-api/error-codes/{api-name}-error-codes
toc_max_heading_level: 4
audience: [consumers, ccg-platform-engineers]
---
import {
CategoryErrorSummary,
CategoryErrorDetails,
ToggleAllErrorsButton
} from '@site/src/components/ErrorCodePage';
import data from './{api-name}-api.json';
# {API Name} Error Codes
This page documents all error codes for the {API Name} (v2).
## Error Summary
### Authorization error
<CategoryErrorSummary data={data} category="Authorization error" />
### Schema validation error
<CategoryErrorSummary data={data} category="Schema validation error" />
## Error Details
<div style={{marginBottom: '1.5rem'}}>
<ToggleAllErrorsButton />
</div>
### Authorization error
<CategoryErrorDetails data={data} category="Authorization error" />
### Schema validation error
<CategoryErrorDetails data={data} category="Schema validation error" />
Add one Summary and one Details block for each category in the JSON. Add ObjectErrorSummary / ObjectErrorDetails blocks for common objects and AllocationErrorSummary / AllocationErrorDetails for allocation errors.
JSON Field Definitionsβ
Required fieldsβ
| Field | Type | Example | Rules |
|---|---|---|---|
id | string | "payment-id-not-found" | Unique within the file, kebab-case |
title | string | "NOT_FOUND" | UPPER_SNAKE_CASE |
httpStatus | string | "404" | String, not number |
message | string | "paymentId not found" | Clear, user-facing |
scenario | array | ["valid paymentId but non-existent"] | One bullet per case |
resolution | string or array | "Verify the paymentId exists" | Actionable guidance |
sampleResponse | object | { "title": "NOT_FOUND", "status": 404 } | Matches the API response |
description | string | "Error returned when paymentId not found" | One sentence |
Optional fieldsβ
The component renders all three of these when present; the real data files use all of them.
| Field | Type | When to use |
|---|---|---|
scopeWithEndPoint | array of { scope: [endpoints] } | Which scope and endpoint combinations return this error. Preferred for new errors. |
endpoints | array of strings | Endpoints that return the error, when scope is not relevant |
scopes | array of strings | Scopes that can see the error, when endpoints are not relevant |
allocationErrors | array | Allocation-level error groups; see below |
Error Categoriesβ
The component matches category by exact string equality with the JSON categories[].name (CategoryErrorSummary / CategoryErrorDetails find the category by name; an unmatched name renders nothing). There is no fixed global list, and casing differs between files, so always copy the name from the API's JSON.
| Category (lifecycle stage) | Use when | Name used in the current data |
|---|---|---|
| Authorization error | API Gateway blocks the request (OAuth, scope, merchant linking) | Authorization error (payment, refund); Authorization Error (session) |
| Resource Not Found error | Invalid ID, non-existent resource, cross-merchant access | Resource Not Found error (payment, refund); Resource Not Found Error (session) |
| Schema validation error | Missing fields, invalid JSON, type mismatches | Schema validation error (payment, refund, common objects) |
| Business rule violation | Domain logic fails (refund greater than payment, duplicate ID) | Business Rule Violation Error (payment, session, common objects); Business rule violation error (refund) |
| Payment processor | Processor-level failure | Payment Processor Validation (payment); Payment processor error (refund) |
Decision tree:
Does the request reach CCG Platform?
ββ No β Authorization error (API Gateway blocks it)
ββ Yes β Does the resource exist?
ββ No β Resource Not Found error
ββ Yes β Is the request structure valid?
ββ No β Schema validation error
ββ Yes β Does it pass business rules?
ββ No β Business rule violation
ββ Yes β Processor interaction
ββ Parent-level failure β Payment processor category
ββ Allocation-level failure β Allocation errors (allocationErrors)
Creating Common Error Objectsβ
Create a common object when an object (such as customer or payment) appears in several APIs with consistent validation rules, so its errors have one source of truth.
- Create
common/{object-name}-object.json:
{
"objectName": "Customer Object",
"description": "Validation errors for the customer object.",
"categories": [
{
"name": "Schema validation error",
"errors": [
{
"id": "customer-hsid-invalid-format",
"title": "INVALID_REQUEST",
"httpStatus": "400",
"message": "customer.hsid must be a valid UUID format",
"scenario": ["When customer.hsid is not in UUID format"],
"resolution": "Ensure customer.hsid is a valid UUID.",
"scopeWithEndPoint": [{ "merchant": ["POST /v2/payments"] }],
"sampleResponse": {
"title": "INVALID_REQUEST",
"status": 400,
"detail": "customer.hsid must be a valid UUID format"
},
"description": "Error returned when customer.hsid format is invalid."
}
]
}
]
}
- Register the object name in the API JSON's
commonObjectsarray, for example"commonObjects": ["customer-object", "payment-object"]. - Import it in the MDX:
import customerObject from './common/customer-object.json'; - Render it under the matching category in both sections. Pass
categorywhen the object has more than one:
#### Customer Object
<ObjectErrorSummary object={customerObject} category="Schema validation error" />
<ObjectErrorDetails object={customerObject} category="Schema validation error" />
Put the Summary call in the Error Summary section and the Details call in the Error Details section.
Documenting Allocation Errorsβ
Allocation errors apply to split tender operations where a parent transaction spawns several allocations that can fail independently with processor-specific codes. Use them when errors occur inside paymentAllocations[] or refundAllocations[].
allocationErrors belongs on the parent error object that represents the multi-allocation failure (in payment-api.json, the error inside the processor category). It is not a root-level field. Group entries by label (an error family), each with several processor code samples. sampleResponse in each entry is an array.
{
"id": "payment-processor-error",
"description": "Error returned when all paymentAllocations failed during processing.",
"allocationErrors": [
{
"label": "card_declined",
"description": "Card was declined without a specific reason. Customer should try a different payment method.",
"scenario": [
"This can happen when the payment processor returns:",
"card_declined: Card was declined for an unspecified reason"
],
"sampleResponse": [
{
"error": {
"title": "PAYMENT_ERROR",
"detail": "Payment method could not be authorized. Please try a different payment method.",
"errorDetails": { "code": "card_declined" }
}
}
]
}
]
}
Group by merchant action or customer messaging:
| Label | Use for | Example processor codes |
|---|---|---|
card_declined | Generic decline | card_declined, card_error, generic_decline |
insufficient_funds | Not enough balance | insufficient_funds |
expired_card | Expired card | expired_card |
invalid_card | Invalid number or details | invalid_number, incorrect_cvc |
blocked_card | Blocked or restricted | lost_card, stolen_card |
issuer_authorization_required | Issuer declined for security | do_not_honor, pickup_card |
If an error does not fit an existing label, add a new label named for the user action or error family.
In the MDX, render the components under their own headings in both sections, with a tip noting that allocation-level HTTP status is inherited from the parent response (see payment-error-codes.mdx for the exact admonitions):
### PaymentAllocation processor error
<AllocationErrorSummary data={data} />
Use <AllocationErrorDetails data={data} /> in the Error Details section. Include a caution that only known combinations are listed and that error.errorDetails reflects vendor data whose structure is not guaranteed.
Best Practicesβ
JSON
- Use kebab-case
id(customer-hsid-invalid-format), UPPER_SNAKE_CASEtitle, and string HTTP status codes ("404"). - Write clear, actionable
messageandresolutionvalues; cover every edge case inscenario. - Keep
descriptionto one sentence (it feeds the summary tables). - Always include a
sampleResponse; never include internal error codes or stack traces. - Do not duplicate errors across common objects and API files.
MDX
- Keep the Summary section before Details, with the same category order in both.
- Import only the common objects you use.
- Include the
ToggleAllErrorsButtonin Error Details and an introduction saying what the page covers. - Never hardcode error details in MDX; use JSON and the components.
- Use one MDX page per API version.
Naming
| Item | Convention | Example |
|---|---|---|
| MDX file | {api-name}-error-codes.mdx | payment-error-codes.mdx |
| JSON file | {api-name}-api.json | payment-api.json |
| Common object | {object-name}-object.json | customer-object.json |
| Error ID | {object}-{field}-{issue} | customer-hsid-invalid-format |
| Allocation label | snake_case error family | insufficient_funds |
Validation Checklistβ
- All required fields present on every error; IDs unique and kebab-case; titles UPPER_SNAKE_CASE; HTTP status is a string
- Sample responses match the real API response; JSON is valid
- Common objects used by the page are listed in
commonObjectsand imported in the MDX - MDX frontmatter has
sidebar_position,slug,toc_max_heading_level, andaudience: [consumers, ccg-platform-engineers] - Every
categorystring matches the JSONnameexactly (case-sensitive) - Summary comes before Details; Toggle All button is present; allocation components are included where relevant
- No internal implementation details are exposed
- The page renders in
yarn start, andyarn -s lint:docspasses
FAQsβ
Can an error appear in several categories? Yes; add separate error objects under each category.
Same error across several APIs? Use a common object if the validation is identical; otherwise duplicate it in each API's JSON with API-specific details.
Updating an error message? Edit the JSON only; the MDX reflects it.
Processor codes that vary by vendor? List the variants in scenario, show several sampleResponse entries, and include the vendor-structure caveat.
Every HTTP status? Document application-level errors only. Generic infrastructure errors (500, 503) need no entry unless there is app-specific context.
Custom sections in the MDX? Yes, with clear headings, but keep the Summary then Details structure.
Troubleshootingβ
Component renders nothing or raw JSON
- Check the
categorystring against the JSONname(case-sensitive;Payment Processor Validationis notPayment Processor Error). - Check the JSON import path and syntax, and the browser console.
Error missing from the summary table
- Verify the category name and that the error sits in the right category array.
- Check
descriptionis present; clear the cache withyarn clear && yarn start.
Sample response not formatting
sampleResponsemust be an object (an array forallocationErrorsentries); check JSON syntax.
Allocation errors not showing
allocationErrorsmust be on the parent error object insidecategories[].errors[], not at the root.- Each entry needs
labelanddescription, andsampleResponsemust be an array.
Referenceβ
- Payment Error Codes is the full working example (common objects and allocation errors).
- Integration Document Guidelines
- Business Use Case Guidelines