Youniton Docs

Errors

Every error has one shape: an RFC 9457 problem document with a stable code. Branch on the code, never on the text.

#The problem shape

Every answer that is not 2xx has the content type application/problem+json.

422 Unprocessable Content
{
  "type": "https://youniton.example/problems/validation.failed",
  "title": "The request is not valid.",
  "status": 422,
  "detail": "Two fields need attention.",
  "instance": "urn:kanso:request:0192f1b2-55aa-7c21-8d0e-1f3a9b6c2d40",
  "code": "validation.failed",
  "traceId": "4bf92f3577b34da6a3ce929d0e0e4736",
  "errors": [
    { "pointer": "/title", "code": "ticket.title_too_long", "detail": "Use at most 200 characters." },
    { "parameter": "filter[stageId]", "code": "query.invalid", "detail": "This stage is not on the board." }
  ]
}
MemberMeaning
codeThe stable machine code, <area>.<reason> in snake_case. Your code branches on it.
statusThe HTTP status again.
title, detailText for people. title is fixed per code. detail follows Accept-Language (English, Lithuanian, German). Do not parse it.
instanceThe URN of your request. It equals the X-Request-Id header. Give it to support.
traceIdThe trace id, for support.
errors[]For 422 and query errors: one entry per problem, with a pointer (a JSON Pointer into your body), a parameter or a header, and its own code.
extensionsSome codes add members: currentVersion (stale-version), capability (access.forbidden), dimension, used, max (limit.reached), limiter (rate_limit.exceeded), reason, ability.

A problem never holds a stack trace, SQL or anything that tells you that a hidden record exists.

#Common status codes

StatusCodeWhat to do
400request.malformed · query.invalid · query.cursor_invalid · idempotency.key_requiredFix the request. A cursor is bound to its filters; start again without it.
401auth.unauthenticatedThe token is wrong, expired or revoked. Stop and get a new token.
403access.forbidden (with capability)You can see the record, but you may not do this action.
403service_token.not_allowed_hereUse the right kind of token for this operation.
403help_desk.ability_missing (with ability) · help_desk.connection_pausedThe help-desk connection does not have the ability, or an Admin paused it.
403feature.unavailable (with reason) · tenant.suspendedThe feature is off for the tenant, or the tenant is suspended.
404<entity>.not_found · route.not_found · tenant.not_foundThe record does not exist, or you cannot see it. Youniton gives the same answer for both.
409<aggregate>.invalid_state · limit.reached · idempotency.in_flightRead the record again. For idempotency.in_flight, wait for Retry-After and retry with the same key.
412stale-version (with currentVersion)Someone changed the record. Read it again and apply your change to the new version.
413request.too_largeSend a smaller body. JSON bodies are at most 1 MiB (2 MiB with a rich-text document).
422validation.failed · idempotency.key_reusedFix the fields in errors[]. Use a new key for a different request.
428precondition.requiredSend If-Match with the version.
429rate_limit.exceeded (with limiter)Wait for the seconds in Retry-After, then retry.
500server.errorRetry later with the same Idempotency-Key. Give the instance to support.
503service.unavailableWait for Retry-After, then retry.

#Why a hidden record answers 404

A 403 would tell you that a record exists. So a record that you may not see answers 404, the same as a missing record, in status, body and time. 403 is only for a record that you can see but may not change.

#Codes of the modules

Each module adds its own codes. Some examples:

StatusCodeWhen
403help_desk.ability_missingthe help-desk connection does not have the ability of the operation
409help_desk_request.external_reference_exists (with requestKey)a create with a known external reference and another body
409help_desk_request.closed_for_messagesa reply on a request that takes no more messages
409file.not_ready · file.intent_expired · file.too_many_open_intentsa file is still in its scan; an upload intent is older than one hour; too many open uploads
422file.type_not_accepted · file.too_largethe file type is not on the accept list, or the file is too large
409memory.path_taken · memory.directory_not_emptyan entry already has the path; a directory still holds entries
422memory.path_invalid · memory.body_too_largethe path breaks the path rules; the Markdown body is too large
422spending.category_unknownthe spending category is not an active category of the tenant
422token.expiry_exceeds_policya token expiry above the tenant's maximum

The reference lists the statuses of each operation. The specification of each feature lists its codes.

#Handle errors in code

Branch on problem.code
const res = await fetch(url, options);
if (!res.ok) {
  const problem = await res.json(); // application/problem+json
  switch (problem.code) {
    case "rate_limit.exceeded":
      await sleep(Number(res.headers.get("Retry-After")) * 1000);
      return retry();
    case "stale-version":
      return reloadAndReapply(problem.currentVersion);
    default:
      throw new Error(`${problem.code} (${problem.instance})`);
  }
}

Was this helpful?