From 491066c48263e238a0aaa6ca8b24c1b5456cec55 Mon Sep 17 00:00:00 2001 From: Reshma Bidikar <85998496+reshmabidikar@users.noreply.github.com> Date: Tue, 24 Nov 2026 14:06:18 +0530 Subject: [PATCH 1/2] Move docs outside insider preview --- html5/_main_toc.html.slim | 18 +- .../aviate-billing-account.adoc | 2 - userguide/aviate/aviate-error-handling.adoc | 257 ++++++++++++++++++ .../aviate-revenue-recognition.adoc | 2 - userguide/preview/aviate-error-handling.adoc | 234 ---------------- 5 files changed, 266 insertions(+), 247 deletions(-) rename userguide/{preview => aviate}/aviate-billing-account.adoc (99%) create mode 100644 userguide/aviate/aviate-error-handling.adoc rename userguide/{preview => aviate}/aviate-revenue-recognition.adoc (99%) delete mode 100644 userguide/preview/aviate-error-handling.adoc diff --git a/html5/_main_toc.html.slim b/html5/_main_toc.html.slim index 8dad25400..9fc86129b 100644 --- a/html5/_main_toc.html.slim +++ b/html5/_main_toc.html.slim @@ -375,6 +375,9 @@ nav.sidebar-nav li a.nav-link href="/latest/aviate-coupons.html" | Coupons + li + a.nav-link href="/latest/aviate-billing-account.html" + | Billing Accounts li a.nav-link href="/latest/aviate-tax.html" | Tax @@ -384,9 +387,15 @@ nav.sidebar-nav li a.nav-link href="/latest/aviate-tax-tutorial.html" | Tax Tutorial + li + a.nav-link href="/latest/aviate-revenue-recognition.html" + | Revenue Recognition li a.nav-link href="/latest/aviate-billing-operations.html" | Billing Operations Demo + li + a.nav-link href="/latest/aviate-error-handling.html" + | Error Handling li.sidebar-divider span.sidebar-divider-label | Insider Preview @@ -399,21 +408,12 @@ nav.sidebar-nav li a.nav-link href="/latest/aviate-approvals.html" | Approvals - li - a.nav-link href="/latest/aviate-revenue-recognition.html" - | Revenue Recognition li a.nav-link href="/latest/aviate-usage-rating.html" | Usage Rating - li - a.nav-link href="/latest/aviate-billing-account.html" - | Billing Accounts li a.nav-link href="/latest/aviate-intents.html" | Intents - li - a.nav-link href="/latest/aviate-error-handling.html" - | Error Handling li .icon-title a.bd-toc-link.main-link role="button" diff --git a/userguide/preview/aviate-billing-account.adoc b/userguide/aviate/aviate-billing-account.adoc similarity index 99% rename from userguide/preview/aviate-billing-account.adoc rename to userguide/aviate/aviate-billing-account.adoc index 752e33dc0..7381b5b6b 100644 --- a/userguide/preview/aviate-billing-account.adoc +++ b/userguide/aviate/aviate-billing-account.adoc @@ -1,7 +1,5 @@ = Aviate Billing Accounts -include::{sourcedir}/includes/insider-preview-card.adoc[] - == Overview A billing account links to a Kill Bill account and stores company contact information, address, and tax registrations. Billing accounts are a prerequisite for: diff --git a/userguide/aviate/aviate-error-handling.adoc b/userguide/aviate/aviate-error-handling.adoc new file mode 100644 index 000000000..7384a3de0 --- /dev/null +++ b/userguide/aviate/aviate-error-handling.adoc @@ -0,0 +1,257 @@ += Aviate Error Handling + +== Introduction + +Aviate can return errors in the https://www.rfc-editor.org/rfc/rfc7807[RFC 7807 Problem Details] format. This gives you a machine-readable error structure that you can handle consistently in your client code. + +A Problem Details response can include these fields: + +* `type` -- a URI identifying the error category +* `title` -- a short, human-readable summary of the error category +* `status` -- the HTTP status code +* `detail` -- a human-readable explanation of what went wrong +* `instance` -- the request path that produced the error (only included by some endpoints) + +Fields without a value are left out of the response. Problem Details responses use the `application/problem+json` content type. + +[NOTE] +==== +Problem Details support is being rolled out across the Aviate APIs. At the time of writing, it is available for the catalog (`/v1/catalog`), metering (`/v1/metering`), billing account (`/v1/ba`), rating (`/v1/rating`) and revenue (`/v1/revenue`) APIs. Other Aviate APIs return the HTTP status code with either an empty body, a plain-text message or a JSON body specific to that endpoint. +==== + +== Requesting Problem Details + +Problem Details are returned only when the client asks for them, by including `application/problem+json` in the `Accept` header: + +[source,bash] +---- +curl -X POST "${KB_URL}/plugins/aviate-plugin/v1/metering/billingMeters" \ + -H "Authorization: Bearer ${ID_TOKEN}" \ + -H "X-Killbill-ApiKey: ${API_KEY}" \ + -H "X-Killbill-ApiSecret: ${API_SECRET}" \ + -H "Content-Type: application/json" \ + -H "Accept: application/problem+json" \ + -d '[{ "code": "api.calls", "name": "API Calls", "aggregationType": "COUNT", "unitType": "request" }]' +---- + +Response (`400 Bad Request`): + +[source,json] +---- +{ + "type": "https://aviate.killbill.io/problems/metering-validation-error", + "title": "Metering Validation Error", + "status": 400, + "detail": "Special characters not allowed in meter code api.calls", + "instance": "/v1/metering/billingMeters" +} +---- + +If the `Accept` header does not include `application/problem+json`, the same request returns only the HTTP status code. Some errors also include a short plain-text message in the body. + +The one exception is a request that fails authentication: it always gets a Problem Details response (see <>). + +== Error Types + +All `type` URIs start with `https://aviate.killbill.io/problems/`. + +[cols="2,1,3", options="header"] +|=== +| Type | HTTP Status | Description + +| `validation-error` +| 400 +| The request is invalid, for example a missing or incorrect field + +| `metering-validation-error` +| 400 +| A billing meter in the request is invalid + +| `catalog-validation-error` +| 400 +| A catalog entity in the request is invalid + +| `quote-error` +| 400 +| A quote or quote item in the request is invalid + +| `unauthorized` +| 401 +| Missing or invalid authentication credentials + +| `forbidden` +| 403 +| The caller does not have the permission needed for this operation + +| `not-found` +| 404 +| The referenced entity does not exist + +| `conflict` +| 409 +| The operation conflicts with existing data, for example an entity that already exists or an accounting period that is already closed + +| `internal-error` +| 500 +| An unexpected server error occurred +|=== + +Some validation errors are reported with the generic `validation-error` type even when a more specific type exists. For example, catalog validation errors currently use `validation-error`. If your client needs to tell errors apart, check `status` first and use `type` only for extra detail. + +== Validation Errors + +Validation errors return `400 Bad Request`. The `detail` field describes the first problem found. For example, uploading catalog data without any plan (`POST /v1/catalog/inputData`) returns: + +[source,json] +---- +{ + "type": "https://aviate.killbill.io/problems/validation-error", + "title": "Validation Error", + "status": 400, + "detail": "Need to specify at least one plan" +} +---- + +== Not Found Errors + +Requesting a billing meter that does not exist (`GET /v1/metering/api-calls/billingMeter`) returns: + +[source,json] +---- +{ + "type": "https://aviate.killbill.io/problems/not-found", + "title": "Not Found", + "status": 404, + "detail": "Billing meter not found: api-calls" +} +---- + +== Conflict Errors + +A `409 Conflict` is returned when the operation clashes with the current data. For example, closing an accounting period that is already closed (`POST /v1/revenue/periods/2026-03/close`) returns: + +[source,json] +---- +{ + "type": "https://aviate.killbill.io/problems/conflict", + "title": "Conflict", + "status": 409, + "detail": "Accounting period already closed: 2026-03" +} +---- + +To recover, fetch the latest state of the entity and decide whether the operation is still needed. + +== Authentication and Permission Errors + +A request with missing or invalid credentials returns `401 Unauthorized`. This response always uses the Problem Details format, whatever the `Accept` header: + +[source,json] +---- +{ + "type": "https://aviate.killbill.io/problems/unauthorized", + "title": "Unauthorized", + "status": 401, + "detail": "Unauthorized" +} +---- + +A request from a user who lacks the required permission returns `403 Forbidden`. The `detail` says whether an Aviate permission or a Kill Bill permission is missing: + +[source,json] +---- +{ + "type": "https://aviate.killbill.io/problems/forbidden", + "title": "Forbidden", + "status": 403, + "detail": "Missing Aviate permission" +} +---- + +Without `application/problem+json` in the `Accept` header, the `403` response body contains only the plain-text message (for example `Missing Aviate permission`). + +== Discount Policy Violations + +When a quote is updated (`POST /v1/quote/{id}`) or submitted (`POST /v1/quote/{id}/submit`) with a discount above the maximum allowed by the discount policy, Aviate returns `422 Unprocessable Entity`. This response is always returned as JSON, whatever the `Accept` header, and lists every violation in a `violations` array: + +[source,json] +---- +{ + "type": "https://developer.killbill.io/errors/discount-policy-violation", + "title": "Discount policy violation", + "status": 422, + "detail": "Item 0: 30% discount exceeds the 20% maximum for your role.", + "violations": [ + { "itemIndex": 0, "ruleId": "sales-rep-limit", "effectiveDiscountPct": 30.0, "maxDiscountPct": 20.0 } + ] +} +---- + +== Handling Errors in Client Code + +Since not every endpoint returns Problem Details yet, check the `Content-Type` of an error response before parsing it. + +=== Bash / curl + +[source,bash] +---- +response=$(curl -s -w "\n%{http_code}" \ + -X POST "${KB_URL}/plugins/aviate-plugin/v1/metering/billingMeters" \ + -H "Authorization: Bearer ${ID_TOKEN}" \ + -H "X-Killbill-ApiKey: ${API_KEY}" \ + -H "X-Killbill-ApiSecret: ${API_SECRET}" \ + -H "Content-Type: application/json" \ + -H "Accept: application/problem+json" \ + -d '[{ "code": "api.calls", "name": "API Calls", "aggregationType": "COUNT", "unitType": "request" }]') + +http_code=$(echo "$response" | tail -1) +body=$(echo "$response" | sed '$d') + +if [ "$http_code" -ge 400 ]; then + echo "Error ($http_code):" + # Print the detail if the body is Problem Details JSON, otherwise the raw body + echo "$body" | jq -r '.detail' 2>/dev/null || echo "$body" +fi +---- + +=== JavaScript / Node.js + +[source,javascript] +---- +const response = await fetch(`${KB_URL}/plugins/aviate-plugin/v1/metering/billingMeters`, { + method: 'POST', + headers: { + 'Authorization': `Bearer ${idToken}`, + 'X-Killbill-ApiKey': apiKey, + 'X-Killbill-ApiSecret': apiSecret, + 'Content-Type': 'application/json', + 'Accept': 'application/problem+json' + }, + body: JSON.stringify([{ code: 'api-calls', name: 'API Calls', aggregationType: 'COUNT', unitType: 'request' }]) +}); + +if (!response.ok) { + const contentType = response.headers.get('Content-Type') || ''; + + if (contentType.includes('json')) { + const problem = await response.json(); + console.error(`${problem.title}: ${problem.detail}`); + } else { + console.error(`HTTP ${response.status}: ${await response.text()}`); + } + + // Handle specific cases by status code + switch (response.status) { + case 400: + // Fix the input and retry + break; + case 401: + case 403: + // Check the credentials and the user's permissions + break; + case 409: + // Refresh the entity state and adjust the operation + break; + } +} +---- diff --git a/userguide/preview/aviate-revenue-recognition.adoc b/userguide/aviate/aviate-revenue-recognition.adoc similarity index 99% rename from userguide/preview/aviate-revenue-recognition.adoc rename to userguide/aviate/aviate-revenue-recognition.adoc index 16135de6d..9d8d775e8 100644 --- a/userguide/preview/aviate-revenue-recognition.adoc +++ b/userguide/aviate/aviate-revenue-recognition.adoc @@ -1,7 +1,5 @@ = Aviate Revenue Recognition -include::{sourcedir}/includes/insider-preview-card.adoc[] - [NOTE] *Beta.* Revenue Recognition is an Insider Preview (beta) feature. Its behavior, API and screens can change between releases. The amounts, identifiers and screens on this page are examples, some of them produced with sample data. Always check revenue figures against your own invoices before you use them to close a month, and send your feedback through Kill Bill support. diff --git a/userguide/preview/aviate-error-handling.adoc b/userguide/preview/aviate-error-handling.adoc deleted file mode 100644 index 9311a5467..000000000 --- a/userguide/preview/aviate-error-handling.adoc +++ /dev/null @@ -1,234 +0,0 @@ -= Aviate Error Handling - -include::{sourcedir}/includes/insider-preview-card.adoc[] - -== Introduction - -All Aviate API errors use the https://www.rfc-editor.org/rfc/rfc7807[RFC 7807 Problem Details] format. This provides a consistent, machine-readable error structure across every endpoint, making it straightforward to handle errors in your client code. - -Every error response includes: - -* `type` -- a URI identifying the error category -* `title` -- a short, human-readable summary -* `status` -- the HTTP status code -* `detail` -- a human-readable explanation of what went wrong -* `instance` -- the request path that produced the error - -The `Content-Type` of all error responses is `application/problem+json`. - -== Error Response Format - -[source,json] ----- -{ - "type": "https://docs.killbill.io/errors/validation-error", - "title": "Validation Failed", - "status": 400, - "detail": "One or more fields failed validation", - "instance": "/plugins/aviate-plugin/v1/intents", - "errors": [ - { "field": "params.account.email", "message": "must be a valid email address" }, - { "field": "params.account.currency", "message": "must not be null" } - ] -} ----- - -== Common Error Types - -[cols="1,1,3", options="header"] -|=== -| Type | HTTP Status | Description - -| `validation-error` -| 400 -| One or more request fields are invalid or missing - -| `invalid-state-transition` -| 409 -| The requested operation is not allowed in the entity's current state - -| `not-found` -| 404 -| The referenced entity does not exist - -| `conflict` -| 409 -| A conflicting entity already exists (e.g., duplicate external key) - -| `forbidden` -| 403 -| The authenticated user does not have permission for this operation - -| `unauthorized` -| 401 -| Missing or invalid authentication credentials - -| `payment-error` -| 402 -| A payment operation failed (e.g., card declined) - -| `rate-limited` -| 429 -| Too many requests -- retry after the indicated interval - -| `internal-error` -| 500 -| An unexpected server error occurred -|=== - -== Validation Errors - -Validation errors include a per-field breakdown in the `errors` array. Each entry identifies the field path and a human-readable message: - -[source,json] ----- -{ - "type": "https://docs.killbill.io/errors/validation-error", - "title": "Validation Failed", - "status": 400, - "detail": "3 validation errors", - "instance": "/plugins/aviate-plugin/v1/catalog/specifications", - "errors": [ - { "field": "name", "message": "must not be blank" }, - { "field": "lifecycleStatus", "message": "must be one of: DRAFT, ACTIVE, RETIRED, OBSOLETE" }, - { "field": "validFor.startDate", "message": "must be a date in the present or future" } - ] -} ----- - -== State Transition Errors - -When you attempt an operation that is invalid for the entity's current state, you receive a `409 Conflict` with details about the current and expected states: - -[source,json] ----- -{ - "type": "https://docs.killbill.io/errors/invalid-state-transition", - "title": "Invalid State Transition", - "status": 409, - "detail": "Cannot close period '2026-03' because it is already CLOSED", - "instance": "/plugins/aviate-plugin/v1/revenue/periods/2026-03/close", - "currentState": "CLOSED", - "allowedTransitions": ["REOPEN"] -} ----- - -Another example -- attempting to accept an already-accepted quote: - -[source,json] ----- -{ - "type": "https://docs.killbill.io/errors/invalid-state-transition", - "title": "Invalid State Transition", - "status": 409, - "detail": "Quote 'qt-abc123' is in state ACCEPTED and cannot transition to ACCEPTED", - "instance": "/plugins/aviate-plugin/v1/quotes/qt-abc123/accept", - "currentState": "ACCEPTED", - "allowedTransitions": [] -} ----- - -== Not Found Errors - -[source,json] ----- -{ - "type": "https://docs.killbill.io/errors/not-found", - "title": "Not Found", - "status": 404, - "detail": "No contract found with id 'ctr-does-not-exist'", - "instance": "/plugins/aviate-plugin/v1/contracts/ctr-does-not-exist" -} ----- - -== Handling Errors in Client Code - -=== Bash / curl - -[source,bash] ----- -response=$(curl -s -w "\n%{http_code}" \ - -X POST "${KB_URL}/plugins/aviate-plugin/v1/intents" \ - -H "Authorization: Bearer ${ID_TOKEN}" \ - -H "X-Killbill-ApiKey: ${API_KEY}" \ - -H "X-Killbill-ApiSecret: ${API_SECRET}" \ - -H "Content-Type: application/json" \ - -d '{ "type": "ONBOARD_CUSTOMER", "params": {} }') - -http_code=$(echo "$response" | tail -1) -body=$(echo "$response" | sed '$d') - -if [ "$http_code" -ge 400 ]; then - echo "Error ($http_code):" - echo "$body" | jq '.detail' - # For validation errors, show per-field details - echo "$body" | jq -r '.errors[]? | " \(.field): \(.message)"' -fi ----- - -=== JavaScript / Node.js - -[source,javascript] ----- -const response = await fetch(`${KB_URL}/plugins/aviate-plugin/v1/intents`, { - method: 'POST', - headers: { - 'Authorization': `Bearer ${idToken}`, - 'X-Killbill-ApiKey': apiKey, - 'X-Killbill-ApiSecret': apiSecret, - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ type: 'ONBOARD_CUSTOMER', params: {} }) -}); - -if (!response.ok) { - const problem = await response.json(); - console.error(`${problem.title}: ${problem.detail}`); - - if (problem.errors) { - for (const err of problem.errors) { - console.error(` ${err.field}: ${err.message}`); - } - } - - // Handle specific error types - switch (problem.type) { - case 'https://docs.killbill.io/errors/validation-error': - // Fix input and retry - break; - case 'https://docs.killbill.io/errors/rate-limited': - // Wait and retry - break; - case 'https://docs.killbill.io/errors/invalid-state-transition': - // Refresh entity state, adjust operation - break; - } -} ----- - -== Rate Limiting - -When the API rate limit is exceeded, the response includes a `Retry-After` header: - -[source,json] ----- -{ - "type": "https://docs.killbill.io/errors/rate-limited", - "title": "Too Many Requests", - "status": 429, - "detail": "Rate limit exceeded. Retry after 30 seconds.", - "instance": "/plugins/aviate-plugin/v1/intents" -} ----- - -HTTP headers: - -[source] ----- -Retry-After: 30 -X-RateLimit-Limit: 100 -X-RateLimit-Remaining: 0 -X-RateLimit-Reset: 1711900030 ----- - -We recommend implementing exponential backoff in your client code when you receive a 429 response. From 2fbddfd96f3167fff51bc7d0fed691d7ac81e634 Mon Sep 17 00:00:00 2001 From: Reshma Bidikar <85998496+reshmabidikar@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:56:09 +0530 Subject: [PATCH 2/2] changes as per copilot comments --- userguide/aviate/aviate-error-handling.adoc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/userguide/aviate/aviate-error-handling.adoc b/userguide/aviate/aviate-error-handling.adoc index 7384a3de0..074deff6f 100644 --- a/userguide/aviate/aviate-error-handling.adoc +++ b/userguide/aviate/aviate-error-handling.adoc @@ -209,8 +209,8 @@ body=$(echo "$response" | sed '$d') if [ "$http_code" -ge 400 ]; then echo "Error ($http_code):" - # Print the detail if the body is Problem Details JSON, otherwise the raw body - echo "$body" | jq -r '.detail' 2>/dev/null || echo "$body" + # Print the detail if the body has one; otherwise (plain text or other JSON) print the raw body + echo "$body" | jq -er '.detail // empty' 2>/dev/null || echo "$body" fi ---- @@ -232,12 +232,16 @@ const response = await fetch(`${KB_URL}/plugins/aviate-plugin/v1/metering/billin if (!response.ok) { const contentType = response.headers.get('Content-Type') || ''; + const body = await response.text(); - if (contentType.includes('json')) { - const problem = await response.json(); - console.error(`${problem.title}: ${problem.detail}`); + if (contentType.includes('application/problem+json')) { + // Problem Details: every field is optional, so fall back to the status code + const problem = JSON.parse(body); + const title = problem.title || `HTTP ${response.status}`; + console.error(problem.detail ? `${title}: ${problem.detail}` : title); } else { - console.error(`HTTP ${response.status}: ${await response.text()}`); + // Plain text or endpoint-specific JSON: print the server's message as-is + console.error(`HTTP ${response.status}: ${body}`); } // Handle specific cases by status code