Karyo
Documentation/ Integration and extension

The error contract

Karyo 2.1.1rendered at build time
On this page

What a failed call returns, how much of it an integrator can key on, and where the contract stops holding. Derived from every ExceptionMapper in the build and from the resources that throw past them.

1. RFC 7807, implemented once and reused

libs/karyo-common/src/main/kotlin/com/karyo/common/exception/ProblemDetail.kt is the single body shape:

data class ProblemDetail(
    val type: String, val title: String, val status: Int, val detail: String,
    val instance: String? = null, val traceId: String? = null,
    val timestamp: Instant = Instant.now(),
)

Twenty-eight @Provider exception-mapper classes, spread over twenty-four files, build it. Seventeen follow one identical shape: a when over a sealed exception hierarchy yielding (status, slug), a type of "https://karyowms.com/errors/$slug", a title derived by title-casing the slug, detail from the exception message, and instance from the injected UriInfo. There is one such mapper per hierarchy: the judgment engine, auth, cross-docking, docstore, document templates, fulfillment, inventory, layout, orders, product, sequence, slotting, stocktaking, streaming, tasks, 3PL billing and waves. The slotting one (SlottingExceptionMapper) maps its three cases to a failing dependency: slotting-engine-not-configured, a 503, when no Loci base URL is configured, since slotting advice requires Loci; and two 502s, slotting-engine-unavailable when a configured Loci slotting engine does not answer or answers with another error status or an unreadable body, when Karyo refuses to send the snapshot because a zone name exceeds Loci's 64-character contract cap or the Loci base URL is malformed, or when Loci's answer is missing a field the envelope needs; and slotting-snapshot-rejected when Loci refuses Karyo's warehouse snapshot as invalid evidence; the detail carries Loci's own findings. The judgment engine's mapper (JudgmentExceptionMapper, ADR 0064) follows the same rule for a hosted engine that Karyo depends on for one answer: judgment-engine-not-configured, a 503, when no engine is switched on or the installation has not opted in; judgment-engine-unavailable, a 502, when a configured engine does not answer, rejects Karyo's key, stays rate-limited past the retries or answers with something unreadable; and judgment-request-rejected, a 502, when the engine refuses the request itself. No route answers with them yet. Eight are single-exception mappers built the same way by hand: ConstraintViolationExceptionMapper, the two label-printer failures (NoPrinterConfiguredExceptionMapper.toResponse, PrinterUnreachableExceptionMapper.toResponse), work's three out-of-hierarchy refusals (WorkClaimConflictMapper.toResponse, OperatorFacilityConflictMapper.toResponse, UnknownWorkingAreaMapper.toResponse) and the two identity-provider failures (IdentityProviderUnavailableMapper, UnsupportedIdentityOperationMapper). The other three mappers, in libs/karyo-common, cover what no domain mapper claims (section 4).

Every ProblemDetail body is served as application/problem+json, the media type RFC 7807 defines for it, whichever mapper or resource built it: ProblemDetailMediaTypeFilter sets it on every response whose entity is a ProblemDetail.

Two limits matter most. There is no extensible property bag and no violations array. And ConstraintViolationExceptionMapper flattens bean-validation failures into a prose detail of propertyPath: message pairs joined by "; " (ConstraintViolationExceptionMapper), which must not be parsed as a field-error contract.

2. One field is always empty

traceId is never set. No mapper in the tree assigns it, and it could not be populated usefully anyway: application.yaml, %prod.quarkus.otel.sdk.disabled sets quarkus.otel.sdk.disabled: true under %prod and %dev.quarkus.otel.enabled sets quarkus.otel.enabled: false under %dev, so no span id exists in either environment Karyo runs in (ADR 0025). The field is on the wire as null in every response.

instance is set by every mapper: it is the request path.

3. Each slug has one meaning and one HTTP status

The type field is the stable identifier a client can key on. Karyo uses https://karyowms.com/errors/<slug>, on the VoyagerForge-controlled domain. Each slug has exactly one meaning and exactly one HTTP status across the application. Modules can reuse a slug only for that same meaning and status; module qualification is not required. A new refusal with a different meaning or status needs a different slug.

The URL path identifies the resource. A 404 means the path's own resource does not exist or is not visible to the caller, including an unknown route. Any other reference in the request input, whether in the body or in a query parameter, to something missing is a 422 invalid-reference, not a 404. A reference the caller cannot see, such as a row of another Business Unit, is refused exactly like a missing one: the same status, slug and wording of detail. This holds for a packaging unit that is missing and for one that does not belong to the stock unit's item. Specific reference slugs also use 422: invalid-unit-load-type, invalid-reference-list, document-template-unknown-client, threepl-billing-unknown-client, permission-action-not-found and organization-node-not-found. The last two name references in access grants and permission profiles, not missing path resources. An ordered list with duplicate ids is malformed input: 400 duplicate-references, distinct from missing rows in that list.

These shared slugs intentionally identify the same refusal across modules:

Slug Produced by
validation-failed ConstraintViolationExceptionMapper (400), MismatchedInputExceptionMapper (400), InventoryExceptionMapper (400), OrderExceptionMapper.toResponse (400), TaskExceptionMapper (400), ProductExceptionMapper (400)
not-found InventoryExceptionMapper, OrderExceptionMapper.toResponse, TaskExceptionMapper, WebApplicationExceptionMapper - all 404
duplicate-name InventoryExceptionMapper, OrderExceptionMapper.toResponse, LayoutExceptionMapper - all 409
has-dependents InventoryExceptionMapper, LayoutExceptionMapper - both 409
not-cancelable OrderExceptionMapper.toResponse, TaskExceptionMapper - both 409
document-not-ready OrderExceptionMapper.toResponse, FulfillmentExceptionMapper - both 409
invalid-state-transition InventoryExceptionMapper, OrderExceptionMapper.toResponse, TaskExceptionMapper - all 409
invalid-reference Orders, tasks, layout, inventory, auth, fulfillment, stocktaking and waves - all 422

ProblemTypeConsistencyTest executes every application exception mapper and its concrete domain exceptions. It rejects any problem type that maps to more than one HTTP status. ErrorContractTest checks missing order and task body references through HTTP, alongside missing path resources that remain 404.

This is a breaking API correction before 2.0.0: all problem type URIs moved to the new domain, and missing body references now return 422 across the affected modules. This includes unit-load create and transfer destinations, target stock and carriers, ASN attachments and lines, fixed-bin and item-area parents, stock-clearance selections, ad-hoc shipping and adopted containers, count campaigns and unit loads, sort carts, home-layout targets, Facility parents, access-grant references, billing previews, document-template Business Units, query-parameter references (GET and DELETE /api/v1/home-layout?facilityId=, /api/v1/home-layout/default?businessUnitId=, GET /api/v1/billing/rate-card?businessUnitId= and GET /api/v1/locations/{id}/distance?to=, previously 404), packaging units on stock-unit creation, goods receiving and change-packaging-unit (a missing packaging unit and one of another item both previously 400 validation-failed), and the unit-load type on a goods-receipt line (previously 404 not-found). Reference lists previously returned 400; they now return 422, while duplicate lists keep 400 under duplicate-references. Clients must update full-URI comparisons and must not retry a missing body reference as a missing path resource.

Legacy cases whose classification remains context-dependent

The body-reference audit leaves these cases unchanged rather than relabelling stored-data or context failures as bad caller input:

Case Current result Why it remains
A stored pick points at missing stock or a missing pick order; a stored carrier tree contains a foreign child 404 from the owning domain mapper The caller names the outer path resource, not the missing stored row. The aggregate cannot be read or acted on safely. Examples: BulkPickService.bulkLines, PickOrderService.confirmPick, UnitLoadService.applyLockRecursive.
A default unit-load type or order strategy is absent 404 not-found The server resolves the default; the caller supplied no body reference. UnitLoadTypeService.defaultTypeId and OrderStrategyService.resolveEntity retain their existing refusal.
The selected Facility disappears after context resolution 404 not-found or layout-not-found This is a request-context race, not a missing body reference. Examples: UnitLoadService.ownerOf, LocationService.create, LocationFinderService.
A day selected by a replay query has no delivery orders 404 not-found The date names a day, not a row. FlowResource treats the replay of that day as the requested resource, and an empty day has none.

These are known exceptions to the strict path-only wording when the failed lookup names an implicit row. They do not give a slug a second status. New request-body reference checks must use 422.

invalid-state-transition means one thing in every module: the record's current state does not allow the move, a 409. Product used to send it as a 422 for a state code that is not a product state at all; that refusal is now its own slug, invalid-product-state (422).

Existing specific slugs - pick-not-found, product-not-found, layout-not-found, count-not-found, document-not-found, user-not-found, client-not-found and business-unit-not-found - remain alongside not-found. Each identifies a missing resource with status 404; clients need not infer module ownership from a slug.

The organization aliases keep their own vocabulary at the error boundary. Business Unit routes use business-unit-not-found (404), duplicate-business-unit (409), and business-unit-administration-forbidden (403); Company mutation by a non-OPS principal uses company-administration-forbidden (403). The legacy client routes continue to use their client slugs.

4. What no domain mapper claims

Three mappers in libs/karyo-common/src/main/kotlin/com/karyo/common/exception/ keep everything else on the contract.

WebApplicationExceptionMapper renders a bare JAX-RS refusal - throw NotFoundException("subscription 5"), throw BadRequestException(reason), and the framework's own 404 for an unknown route and 405 for a wrong method:

  • type is the status's own slug (bad-request, unauthorized, forbidden, not-found, method-not-allowed). The request filter's 403 refusals do not use this rule: the ForbiddenException it throws for an action the caller does not hold, or for an identity denial, already carries a ProblemDetail. Its type is the refusal itself (action-not-granted, or the denial reason).
  • detail is the exception's message - the webhook URL policy's reason, for example - or plain words for the status when the message is blank or the JAX-RS default (HTTP 404 Not Found).
  • The response's headers are kept, so a 401 still carries its WWW-Authenticate challenge. A WebApplicationException that already carries an entity (SystemPropertyResource and the request filter's 403 refusals build their ProblemDetail themselves) is returned as built.

MismatchedInputExceptionMapper turns a request body that parses as JSON but does not fit the request type - a missing required field, a string where a number belongs - into a 400 validation-failed naming the field (Field 'number' is missing or has the wrong type.). It replaces Quarkus's own mapper, whose body was not RFC 7807. A body that is not JSON at all is a 400 bad-request through WebApplicationExceptionMapper.

UnhandledExceptionMapper is bound to Throwable and so receives whatever nothing more specific claims:

  • A lost version check anywhere in the cause chain - OptimisticLockException or Hibernate's StaleStateException - is a 409 concurrent-change, detail "Someone else changed this record at the same time. Refresh and try again." Another request changed the same row first and this transaction rolled back whole, so nothing was applied and a retry is safe. Two operators releasing orders for the same last stock at once meet this (see Allocation and reservation).
  • Otherwise, the first cause in the chain that another mapper claims is mapped by that mapper, so a domain refusal that surfaces wrapped in a commit failure keeps its own status and slug.
  • Anything else is a 500 internal-error whose detail names an error id and nothing else. The exception and its stack trace are logged under that id; neither reaches the caller, in any profile.

Refusals produced before any resource runs carry their own bodies - an authentication failure from the OIDC layer, or nginx's own 404 for /api/internal/ (infrastructure/docker/nginx/nginx.conf, location /api/internal/). Those are outside the application's mappers by construction. A refusal from a Quarkus security annotation is not: @Authenticated throws io.quarkus.security.UnauthorizedException (or ForbiddenException) before the request filter runs, and SecurityRefusalMappers in services/karyo-app answers it with a problem body instead of Quarkus's own short one. An anonymous GET /api/v1/me/operator-context is a 401 unauthorized problem that keeps the WWW-Authenticate: Bearer challenge Quarkus would send. A failure on a route outside JAX-RS reaches Quarkus's own error handler, whose body names an error id and carries a stack trace only in dev and test mode (QuarkusErrorHandler, shown when LaunchMode.isDevOrTest); application.yaml sets nothing that changes that.

5. What a client can actually rely on

Rely on Do not rely on
HTTP status and each problem type identifying one meaning and one status type being module-unique
type, title, status, detail, instance, timestamp on every error raised by the application's own code, a JAX-RS refusal or a Quarkus security-annotation refusal traceId (always null)
application/problem+json as the media type of every such error A structured field-error list; detail is prose
The status families the mappers use: 400 malformed input, 401 no valid credentials, 403 a scope or principal-kind refusal, 404 a missing path resource, 409 a state or concurrency conflict (concurrent-change is safe to retry), 413 an oversized document, 422 a well-formed request the domain refuses, 500 a fault with an error id to quote, 502 or 503 a failing dependency (the Keycloak admin API, a label printer, the Loci slotting engine) The wording of detail, which is written for people

Identity failures

OIDC signature, issuer, algorithm, time and audience failures are 401 responses from the protocol layer. A valid credential whose exact binding is unknown, unlinked, suspended, affiliation-mismatched or outside local authority is 403 and is never auto-enrolled. Identity-store failure is 503 and never falls back to a token subject. A provider administration action that the configured adapter does not support returns a typed 409 capability problem without effects; a supported operation whose provider is unavailable remains a dependency failure, not "unsupported".