CodamAIDocs
Topicdone

Map of status codes

Every status code with the situations in which CDMS returns it: 200, 400, 401, 403, 404, 409, 413, 422, 500, 503.

Variants
200 (including the LENIENT special case)400401403404409413422500503

What this is about

Every response has an HTTP status code, a three-digit number. The first digit tells you who has to act:

  • 2xx: It worked.
  • 4xx: The request does not fit. The client has to change something before a new attempt makes sense.
  • 5xx: Something went wrong in the server. The client cannot improve anything about the request.

Where the codes arise

A request passes through several stations. Each station has its own codes:

The path of a request and its refusals
  1. CIAS
    Filter chain
    Is there a valid token? Can the tenant be determined?
    ↳ no 401 token invalid · 403 no token or tenant refused
  2. CDMS
    Routing
    Does this path exist?
    ↳ no 404 without messageKey
  3. CDMS
    REST layer
    Can the body be read? Are data and response there?
    ↳ no 400 · 413 upload too large
  4. CDMS
    System layer
    Role, visibility, relations, field rules, hooks
    ↳ no 403 · 404 · 400 · 422
  5. Database
    Persistence
    Does the database accept the change?
    ↳ no 409 value already taken or object still referenced · 409 concurrent change · 400 value does not fit the column · 503 database unreachable
  6. 200 with data, the change is committed

When the role and when visibility is checked first is described in 401, 403 or 404?.

The matrix

Codemeanstypical situations and messageKeytry again?
200successfulread, search, create, change, delete, rollback. Special case: created, but not read back (CDMS_CREATE_SUCCEEDED_READ_FAILED)–
400request faultyJSON not readable, value does not fit the field, response or data missing, filter with a wrong value, creating through a relation not allowed, value does not fit the database columnonly after a correction
401token invalidtoken expired, broken or wrongly signedafter renewing the token, once
403not allowedno token, tenant refused, role missing (missing-permission|<role>), tenant switch not allowedno
404not foundobject does not exist or is invisible to you, singleton not created yet, path unknownno
409conflictunique value already taken (already-exists), object still referenced (database-integrity-failed), two requests write new content into the same file object at the same timefor already-exists and database-integrity-failed only after a correction, otherwise after reading again
413upload too largea file (file-too-large|<bytes>), all files together (request-too-large|<bytes>) or the number of parts (too-many-parts|<count>) above the limitonly after a correction
422content breaks rulesfield rules violated (validation-failed with violations), hook refuses, profile attribute missingonly after a correction
500server errorunexpected error in the server or an error in the project’s setupusually pointless
503database unreachablethe database server does not respond, the connection drops, a lock is not released in time, the database aborts a deadlockafter a pause

What is stored after each code and how you retry is described in May the client retry?.

200: successful

Every successful request returns 200, including a create and a delete. Codes like 201 or 204 do not exist. A delete answers with an empty body, everything else with data. See The response format.

There is one special case: in LENIENT mode a create can succeed while only the read-back fails. Then you get 200 with a body in error shape, the messageKey CDMS_CREATE_SUCCEEDED_READ_FAILED and the id of the new object. The object is stored, do not create it again. See Create and read back.

400: the request is faulty

400 means: CDMS cannot execute the request as it is. The messageKey tells you what does not fit, often with the path or field after it.

AreamessageKeyPage
body not readablemalformed-json, unreadable-bodyValidation
value does not fit the fieldinvalid-value|<path>, e.g. text in a number fieldValidation
part of the request missingresponse, missing-data, missing-id, missing-parameterReading an object
path value has the wrong typeinvalid-parameter|<name>, e.g. an id that is not a UUID–
filter or sorting wrongwrong-value-in-where|…, wrong-uuid-in-where|…, like-needs-text|…, wrong-order-element-exceptionWhen a filter does not fit
relation does not allow creatingrecursive-create-not-allowed|<field>The four cases
subtype missing or unknownmissing-type-for-abstract-field|…, unknown-type-for-abstract-field|…Abstract models
the database does not accept a value, e.g. longer than the column or empty in a required columnconstraint-violationValidation
a reference points, when saving, to an object that does not exist (any more)unknown-referenceThe four cases
singleton already existsobject-already-exists|use-updateSingleton
file object without a matching filefile-part-missing|<name>, file-name-missingUploading
tenant missingCDMS_TENANT_REQUIREDWhere the tenant of a request comes from

401 and 403: who you are and what you may do

401 only comes from the filter chain: the token is expired, broken or wrongly signed. The response has no body, but the header WWW-Authenticate: Bearer error="invalid_token". Renew the token and retry the request once.

403 means: this request is not allowed for you. There are three sources:

Sourcehow you recognize itExample
filter chain, no tokenbody without messageKeyheader Authorization missing
filter chain, tenantfield error with cias.authentication.…cias.authentication.tenant-unresolved
CDMSmessageKeymissing-permission|hr-employee-read, without strict mode missing-create-role and others, CDMS_TENANT_SWITCH_NOT_AUTHORIZED

See Access without a token, Model roles and Strict mode.

404: not found

404 with a messageKey means: the object does not exist, or you may not see it. CDMS deliberately does not tell these apart. Typical keys are not-found, not-found|<Dto>|<id>, missing-object|… for a missing child in a relation, and no-data-exists|use-create for a singleton that does not exist yet.

404 without a messageKey means: the path does not exist. Usually the model path is misspelled, or the model does not have this endpoint. See Why invisible objects return 404 and Which endpoints a model has.

409: conflict

409 means: the change does not fit the data that is already stored. Nothing is stored. There are three cases:

SituationmessageKeywhat to do
a unique value or the id is already takenalready-existsdo not retry: the value exists already. Choose another value or change the existing object
another object still points to this one when saving, for example because the reference came into being at the same time. References through the model are cleared by CDMS itself on delete, see Dependent objects (cascades)database-integrity-faileddo not retry: remove the reference first
two requests write new content into the same file object at the same time, and the second one losesCDMS_OPTIMISTIC_LOCK_CONFLICTread the object again, then try again

The concurrent write conflict only exists for file models; for all other models the last change wins without an error. See Concurrent changes.

422: the content breaks rules

422 means: the request is built correctly, but its content breaks a rule.

Three kinds of 422

When: required field empty, text too long, pattern, minimum or maximum value, date

messageKey validation-failed. violations holds all violations of the request, each with field path and rule.

Result: See Getting validation errors into the form.

When: The project's business logic throws a validation error.

layer is hook, the hook chooses the messageKey. There is no violations.

Result: See When a hook fails.

When: An attribute filter needs a value from your profile, and it is missing or empty.

missing-attribute-on-profile|<attribute> or empty-attribute-on-profile|<attribute>, without violations.

Result: Not the data is wrong, but the person's profile. See Attribute filter.

500: error in the server

500 means: something happened in the server that the client cannot fix. There are two kinds:

  • Unexpected error. The messageKey is details see logfiles, layer is undefined. The cause is in the server log.
  • Error in the setup. The project is set up wrongly, and the messageKey names it. Examples: unresolvable-mandatory-filter|… for a filter on a field that does not exist, and CDMS_TENANT_DATASOURCE_NOT_FOUND when the tenant’s database is missing.

An unexpected exception in a hook also ends with 500. A retry does not help in any of these cases. Pass status, messageKey and time on to the team.

503: the database cannot be reached

503 means: the database cannot serve the request right now. Nothing is stored, the transaction has been rolled back. This is a disruption, not a fault in your data: a retry after a pause can succeed.

SituationmessageKey
the tenant’s database server cannot be reachedCDMS_TENANT_DATASOURCE_UNAVAILABLE
the connection drops during the requestdatabase-unavailable|connection
a lock on the object is not released in timedatabase-unavailable|lock-timeout
the database aborts the request because of a deadlock with another onedatabase-unavailable|deadlock

If the database instead rejects a change because of the data already stored, the answer is 409, and an unchanged retry fails the same way. See above.

Refusals when uploading

When uploading files, CDMS refuses a request with 400 if two parts have the same file name (duplicate-filenames|<name>), a part has no file name (missing-filename) or the multipart body cannot be read (malformed-multipart). If a file, the whole request or the number of parts is too large, the answer is 413, and the messageKey names the limit, e.g. file-too-large|26214400 (bytes). Check names and size in the client already. See Uploading and Size limits.

Pitfalls

Where to go next

Sources in the code and the knowledge base
  • CDMS/cdms-rest-api – CdmsExceptionMapper, ClientErrorTranslator, AbstractRestApi, AbstractRestSingletonApi, AbstractHubApi, Expander
  • CDMS/cdms-commons – exceptions (ApiBadRequestException 400, InvalidQueryDefinitionException 400, DatabaseConstraintViolationException 400, RecursiveOperationNotAllowed 400, EntityNotFoundException 404, ApiNotFoundException 404, FileUploadException 413, ApiValidationException 422, HookValidationException 422, DataIntegrityException 409, DatabaseUnavailableException 503, CreateSucceededReadFailedException 200)
  • commons – AbstractCodamaiException, NoAccessException 403, NotFoundException 404, UndefinedInternalException 500
  • commons-persistence – PersistenceErrorCode (CDMS_TENANT_REQUIRED, CDMS_TENANT_SWITCH_NOT_AUTHORIZED, CDMS_OPTIMISTIC_LOCK_CONFLICT, CDMS_TENANT_DATASOURCE_UNAVAILABLE and others)
  • CDMS/cdms-authorization – MissingPermissionException 403, AttributeValidationException 422
  • CDMS/cdms-persistence-database – AbstractDatabasePersistence (createObject, flush, lockForUpdate), PersistenceFailureTranslator, DatabaseHubPersistence.commit, DatabaseConditionBuilder
  • CDMS/cdms-system-layer – AbstractSystemLayer, AbstractLayer
  • CIAS/cias-authentication – SessionConfig, JwtSessionFilter, RequestAdmission
  • documentation/20-api/06-fehler-und-statuscodes.md, 05-api-guide/10-fehler.md
Search