Errors
Both hosts report failures in the vocabulary of Atscript DB, so an app handles an OData service and an Atscript DB backend with the same code. In the browser that is the error classes of @atscript/db-client; behind a Moost server it is Moost DB's error envelope { message, statusCode, code, errors }, which db-client turns into the same classes. What the engine refuses, a 400 or 409 of the service, and a service that fails, times out or throttles go through one mapping (dbFailureOf of @atscript/odata), which gives the server its DbError and the browser the ClientError that server answer becomes: both hosts answer with the same status, code and entries.
import { ClientError, TransportError, VersionMismatchError } from "@atscript/db-client";
try {
await orders.update(patch);
} catch (error) {
if (error instanceof VersionMismatchError) reload();
else if (error instanceof ClientError) showOnForm(error.errors, error.message);
else if (error instanceof TransportError) showOffline();
else throw error;
}At a glance
| What happened | Browser client | Server answer |
|---|---|---|
| A read OData cannot express, or the service forbids | ClientError 400 INVALID_QUERY, the field's code on the entry | 400, the same entry (see below) |
An operation not supported (grouped read without $apply, geo; query targets of actions in the browser) | ClientError 400 NOT_SUPPORTED | 400 NOT_SUPPORTED |
| A filter or sort of a relation on OData v2 | ClientError 400 NOT_SUPPORTED | 400 NOT_SUPPORTED |
| A write the set does not allow | ClientError 400 NOT_SUPPORTED | 400 NOT_SUPPORTED |
| A payload the type rejects | ClientValidationError (400, before any request) | 400 with field paths |
The service answers 400 (a rejected value or filter) | ClientError 400 INVALID_QUERY, the service's messages by field | 400 INVALID_QUERY, the same messages |
The service answers 409 | ClientError 409 CONFLICT, its messages by field | 409 CONFLICT, the same messages |
| The entity changed since the caller's version token | VersionMismatchError (409, currentVersion) | 409 VERSION_MISMATCH, the same body |
| A write without a token met a change three times in a row | ClientError 503 SERIALIZATION_FAILURE | 503 SERIALIZATION_FAILURE |
A write to a set without a version token refused 412 / 428 (a precondition the metadata does not declare) | ClientError with the service's 412 / 428 | 502 STORE_FAILED, entry PRECONDITION_REQUIRED |
| An array insert with refused rows (the others created) | ClientError with the first refused row's status and code, every refused row at [i], INSERTED entries | the same status and body |
A write of a changeset the service refused with 404 (or 412 to *) / 412 to an ETag (nothing in it applied) | ClientError 409 CONFLICT / 503 SERIALIZATION_FAILURE, for every write in it; a 412 to no If-Match as alone | the same, for an action on rows applied all or none |
An explicit batch to a service without $batch | ClientError 400 NOT_SUPPORTED, every call | — |
A missing entity on remove (or update with a token), or a 412 to If-Match: * on a row | ClientError 404 NOT_FOUND | 404 NOT_FOUND |
The service fails (5xx but 501) | ClientError 502 STORE_FAILED | 502 STORE_FAILED |
The service does not implement it (501) | ClientError 400 NOT_SUPPORTED, the service's message | 400 NOT_SUPPORTED, the same message |
The service's gateway times out (504) | ClientError 504 STORE_TIMEOUT | 504 STORE_TIMEOUT |
The service throttles (429) | ClientError 429 STORE_THROTTLED, the wait in params.retryAfter | 429 STORE_THROTTLED, Retry-After |
| The service sends a login page instead of data, or redirects a write | ClientError 401 UNEXPECTED_CONTENT | 502 STORE_FAILED |
The service refuses the credentials (401, 403) | ClientError with that status | 502 STORE_FAILED |
A read needs more pages than maxPages | ClientError 400 INVALID_QUERY on $limit | 400 INVALID_QUERY on $limit |
| Network failure, an unreadable answer | TransportError | 502 STORE_FAILED |
A call aborted or timed out (callTimeout) | TransportError (aborted) | 504 STORE_TIMEOUT |
The live $metadata cannot be read | every call of the service's clients rejects as a data call would; the next call reads again | space.connect() rejects: the app does not start |
| An entity set the live service no longer has | ClientError 404 NOT_FOUND | 404 NOT_FOUND on every endpoint (OData bases) |
A field a read may not use (unknown, not filterable, not sortable) is often refused on the server by Moost DB's own checks, before the adapter: the entry is the same (UNKNOWN_FIELD, FIELD_NOT_PERMITTED with params), while the envelope's code is the entry's and the message is Moost DB's wording. Branch on the entries' code, which both hosts share.
Where the two hosts differ, they do on purpose: the browser calls the service with the user's own session, so a refused credential, a login page or a lost connection is the user's to act on; the server calls it with its own credentials, so the same events are a fault behind the server.
Messages by field
A 400 or 409 of the service is its answer to what the caller sent, worded for the caller, and it reaches the caller on both hosts by one rule (messageEntries of @atscript/odata), the same on OData v2 and v4:
- the service's leading message is the error's
message; it is an entry oferrorswhen its target names a field, and else, when it carries a code (an SAP message id) no detail repeats, an entry at""with that code; - every message with a target is an entry at the field path its target maps to (
/OrderSet('1')/NetAmount→NetAmount,Items(ItemNo='10')/Quantity→Items.Quantity), with the service's code; - a detail without a target is an entry at
"", unless it repeats the leading message; - a pseudo target such as
/#TRANSIENT#(written by SAP Gateway® and the v2 adapter of SAP CAP) counts as none; - warnings and notes sent along with an error are left out.
See it live
Open coffee 17 in the browser app, set Price per kg below the cost and save: the service's message lands on that field. Code: RecordForm.vue.
Show the messages on a form
AsForm takes a map of messages by field path. Messages without a path go to a banner:
<script setup lang="ts">
import { ClientError } from "@atscript/db-client";
import { ref } from "vue";
const errors = ref<Record<string, string>>({});
const banner = ref<string>();
async function save(data: unknown) {
errors.value = {};
banner.value = undefined;
try {
await client.insert(data as Record<string, unknown>);
} catch (error) {
if (!(error instanceof ClientError)) throw error;
for (const entry of error.errors) {
if (entry.path) errors.value[entry.path] = entry.message;
else banner.value = entry.message;
}
banner.value ??= error.message;
}
}
</script>
<template>
<p v-if="banner" role="alert">{{ banner }}</p>
<AsForm :def="def" :form-data="formData" :types="formTypes" :errors="errors" @submit="save" />
</template>A ClientValidationError (the preflight before a write) is a ClientError too, with preflight: true; the form usually catches the same problems first.
Browser client
ODataClient throws only the classes of @atscript/db-client:
ClientErrorfor what the client or the engine refuses before any request, and for what the service answers. What the engine refuses and the service's400,409,429and5xxcarry the status, code and entries a Moost server answers:INVALID_QUERYwith Moost DB's code on the entry (UNKNOWN_FIELD,FIELD_NOT_PERMITTEDwithparams,UNKNOWN_RELATIONat$with) or the engine's (UNSUPPORTED_REGEX,INVALID_VALUE, …),NOT_SUPPORTED(also a501of the service, with its message),CONFLICT,STORE_FAILED,STORE_TIMEOUT,STORE_THROTTLED(the service'sRetry-Afterasparams.retryAfteron the entry, in seconds). The client's own pre-checks answer400NOT_SUPPORTEDwith a code of their own on the entry (CAS_NOT_SUPPORTED,UNSUPPORTED_FIELD_OPERATOR,UNSUPPORTED_ARRAY_OPERATOR; the full list is in the API reference); any other answer of the service (401,403,404, …) keeps its status, code and messages.VersionMismatchErrorfor a write whose version token is stale: the body Moost DB answers, with the entity's current token ascurrentVersion(see Writes).TransportErrorfor a network failure, an aborted call, or a success answer that cannot be read.
A login page answered instead of data (a single sign-on redirect after the session expired) is a 401: send the user to sign in again. A write is never sent on to another address: a redirect answering it (status 3xx, hidden by the browser) is the same 401, since fetch would otherwise repeat it as a GET and take that answer for the write's. A redirect to another origin that carries no CORS headers is a network error instead (a TransportError): the browser checks CORS on the 3xx first, as the Fetch standard says. The 401 holds for a same-origin call and for a redirect that carries CORS headers. The live $metadata read fails the same way: connect() and every call of the service's clients reject with the error a data call would get, and the next call reads again, so a user who signed in again needs no reload.
Server answers
The adapter of @atscript/db-odata reports every failure as a DbError (toDbError), which Moost DB answers by its own rules on any controller over the space: the OData bases, Moost DB's own classes, the ARBAC controllers of Aooth. What the caller can fix is INVALID_QUERY and NOT_SUPPORTED (400) or CONFLICT (409); a call the service did not serve is one of Atscript DB's store-failure codes:
| The service | Answer | code |
|---|---|---|
5xx but 501, no answer, 401 / 403 (the server's credentials), a login page, a redirected write, another status | 502 | STORE_FAILED |
| a write refused for want of a session | 502 | STORE_FAILED |
a precondition its metadata does not declare (428, 412 to no If-Match) | 502 | STORE_FAILED, entry PRECONDITION_REQUIRED |
timed out, or the call was aborted; 504 | 504 | STORE_TIMEOUT |
429 | 429 | STORE_THROTTLED |
- Refused credentials are the server's: the server calls the service with its own technical user (see Credentials and Sessions), so a
401or403of the service is a fault of the server's configuration, hence502. A login page in place of data is too. - A write without a session is one made without credentials, or by a space created with
sessions: false(see Sessions). 429sendsRetry-Afterwhen the service named a wait (seconds, or an HTTP date turned into seconds); the entry carries it asparams.retryAfter.- The message is generic (
The data service failed to answer the request, …) and Moost's translator renders it bycodewhen the app has one. What the service said is not in the body: its texts can name internal objects, hosts and users. - Every
5xxis logged by Moost DB (topicmoost-db) with the service's error as the cause: its status, code, message, the URL called and, for a write without a session, the remedy. A503is logged as a warning, every other5xxas an error. - A set gone live is refused by the OData bases on every endpoint,
/metaincluded, with Moost DB's404NOT_FOUND; under Moost DB's own classes every call of it is a500(see Moost Server). 400and409of the service are not store failures: their messages do reach the caller, asINVALID_QUERYandCONFLICTwith the entries described above. A service that puts internals into these texts needs an interceptor of your own in front.
Operations
An operation answers what the service says as every call does (the table above), and adds these (several rows: see Several rows):
| What happened | Browser client | Moost server |
|---|---|---|
| The parameters do not fit the operation type | ClientValidationError (400, before any call), the field paths | 400, Moost DB's validation envelope, the same entries |
Several rows, some failed (isolated) | The summary (failed: each row's reason, status, code), not an error | 201, the same summary; a row failed with a 5xx is logged, once per distinct answer |
Several rows, every row failed (isolated) | The first row's error, every row's entries at [i] ([1], [1].Note); where the gate skipped rows, or on all matching rows (the server only), the summary with processed: 0 | The same status and body |
Several rows applied all or none (changeSet), refused | One error, nothing applied: 412 to the rows' tokens → 503 SERIALIZATION_FAILURE, 404 (or 412 to *) → 409 CONFLICT, a 412 to no If-Match (a set without a version token) as a single call's; a message that names a row at [i], i its index in the request's ids, with params.id | The same status and body |
Several rows all or none without $batch (batch: false) | ClientError 400 NOT_SUPPORTED, before any call | 400 NOT_SUPPORTED, before any call |
The row changed after its token was read (the service answers 412 on it) | VersionMismatchError (409) with the current token, or 404; of several rows, that row's failed entry (VERSION_MISMATCH) | 409 VERSION_MISMATCH, the same body, or 404; of several rows, the same entry |
| A row that does not exist | ClientError 404 NOT_FOUND: from the token read or the ETag read before the call (a call that writes, on a set with a version token), its call not sent; also where the service answers the call of one row 404. Of several rows, that row's failed entry; under changeSet the run is refused, as a refused changeset (409 CONFLICT, the row at [i]) | The same; where the row load reads the rows, 404 before any call, and on an action with an availability gate 409 (Moost DB's gate counts the row unavailable) |
| More than 50 ids; every row unavailable | Not checked: the service answers | 400; 409 (Moost DB's action gate) |
The engine refuses the call (MISSING_PARAMETER, INVALID_VALUE, …) | ClientError 400 INVALID_QUERY, the engine's code on the entry | 400 INVALID_QUERY, the same entry |
| The live service no longer has the operation | ClientError 400 INVALID_QUERY, UNKNOWN_OPERATION on the entry | 404 NOT_FOUND, after your guards, before any call |
| The live service changed it so that the build no longer fits | Follows the live service | 500, logged, after your guards, before any call |
| An action the client does not list | ActionNotFoundError, before any call | No such route |
A row whose token met a change (412) is that row's 409 VERSION_MISMATCH under isolated, while under changeSet the answer is the changeset's 503 SERIALIZATION_FAILURE, the row the service names at [i] with params.id: the service rolled the whole run back, so every row is to be read and sent again, not that one alone.
DOs and DON'Ts
- Branch on
instanceof ClientError/VersionMismatchError/TransportError— the same code serves both hosts and Atscript DB backends. - Put
error.errorson the form bypath, and the rest in a banner — don't show onlyerror.message. - Treat a
401of the browser client as "sign in again" — it is what an expired session with the service looks like. - Treat a
502STORE_FAILEDof the server as a fault behind the server — the caller cannot fix it by signing in; read the server's log for the cause. - Offer a retry on
503SERIALIZATION_FAILUREand afterparams.retryAfteron429— don't retry a502in a loop. - Read
failedof an action's summary on several rows — a run whose rows go out each on its own succeeds when one of them ran.