Skip to content

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.

ts
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 happenedBrowser clientServer answer
A read OData cannot express, or the service forbidsClientError 400 INVALID_QUERY, the field's code on the entry400, the same entry (see below)
An operation not supported (grouped read without $apply, geo; query targets of actions in the browser)ClientError 400 NOT_SUPPORTED400 NOT_SUPPORTED
A filter or sort of a relation on OData v2ClientError 400 NOT_SUPPORTED400 NOT_SUPPORTED
A write the set does not allowClientError 400 NOT_SUPPORTED400 NOT_SUPPORTED
A payload the type rejectsClientValidationError (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 field400 INVALID_QUERY, the same messages
The service answers 409ClientError 409 CONFLICT, its messages by field409 CONFLICT, the same messages
The entity changed since the caller's version tokenVersionMismatchError (409, currentVersion)409 VERSION_MISMATCH, the same body
A write without a token met a change three times in a rowClientError 503 SERIALIZATION_FAILURE503 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 / 428502 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 entriesthe 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 alonethe same, for an action on rows applied all or none
An explicit batch to a service without $batchClientError 400 NOT_SUPPORTED, every call—
A missing entity on remove (or update with a token), or a 412 to If-Match: * on a rowClientError 404 NOT_FOUND404 NOT_FOUND
The service fails (5xx but 501)ClientError 502 STORE_FAILED502 STORE_FAILED
The service does not implement it (501)ClientError 400 NOT_SUPPORTED, the service's message400 NOT_SUPPORTED, the same message
The service's gateway times out (504)ClientError 504 STORE_TIMEOUT504 STORE_TIMEOUT
The service throttles (429)ClientError 429 STORE_THROTTLED, the wait in params.retryAfter429 STORE_THROTTLED, Retry-After
The service sends a login page instead of data, or redirects a writeClientError 401 UNEXPECTED_CONTENT502 STORE_FAILED
The service refuses the credentials (401, 403)ClientError with that status502 STORE_FAILED
A read needs more pages than maxPagesClientError 400 INVALID_QUERY on $limit400 INVALID_QUERY on $limit
Network failure, an unreadable answerTransportError502 STORE_FAILED
A call aborted or timed out (callTimeout)TransportError (aborted)504 STORE_TIMEOUT
The live $metadata cannot be readevery call of the service's clients rejects as a data call would; the next call reads againspace.connect() rejects: the app does not start
An entity set the live service no longer hasClientError 404 NOT_FOUND404 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 of errors when 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:

vue
<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:

  • ClientError for what the client or the engine refuses before any request, and for what the service answers. What the engine refuses and the service's 400, 409, 429 and 5xx carry the status, code and entries a Moost server answers: INVALID_QUERY with Moost DB's code on the entry (UNKNOWN_FIELD, FIELD_NOT_PERMITTED with params, UNKNOWN_RELATION at $with) or the engine's (UNSUPPORTED_REGEX, INVALID_VALUE, …), NOT_SUPPORTED (also a 501 of the service, with its message), CONFLICT, STORE_FAILED, STORE_TIMEOUT, STORE_THROTTLED (the service's Retry-After as params.retryAfter on the entry, in seconds). The client's own pre-checks answer 400 NOT_SUPPORTED with 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.
  • VersionMismatchError for a write whose version token is stale: the body Moost DB answers, with the entity's current token as currentVersion (see Writes).
  • TransportError for 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 serviceAnswercode
5xx but 501, no answer, 401 / 403 (the server's credentials), a login page, a redirected write, another status502STORE_FAILED
a write refused for want of a session502STORE_FAILED
a precondition its metadata does not declare (428, 412 to no If-Match)502STORE_FAILED, entry PRECONDITION_REQUIRED
timed out, or the call was aborted; 504504STORE_TIMEOUT
429429STORE_THROTTLED
  • Refused credentials are the server's: the server calls the service with its own technical user (see Credentials and Sessions), so a 401 or 403 of the service is a fault of the server's configuration, hence 502. 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).
  • 429 sends Retry-After when the service named a wait (seconds, or an HTTP date turned into seconds); the entry carries it as params.retryAfter.
  • The message is generic (The data service failed to answer the request, …) and Moost's translator renders it by code when the app has one. What the service said is not in the body: its texts can name internal objects, hosts and users.
  • Every 5xx is logged by Moost DB (topic moost-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. A 503 is logged as a warning, every other 5xx as an error.
  • A set gone live is refused by the OData bases on every endpoint, /meta included, with Moost DB's 404 NOT_FOUND; under Moost DB's own classes every call of it is a 500 (see Moost Server).
  • 400 and 409 of the service are not store failures: their messages do reach the caller, as INVALID_QUERY and CONFLICT with 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 happenedBrowser clientMoost server
The parameters do not fit the operation typeClientValidationError (400, before any call), the field paths400, Moost DB's validation envelope, the same entries
Several rows, some failed (isolated)The summary (failed: each row's reason, status, code), not an error201, 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: 0The same status and body
Several rows applied all or none (changeSet), refusedOne 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.idThe same status and body
Several rows all or none without $batch (batch: false)ClientError 400 NOT_SUPPORTED, before any call400 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 existClientError 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 unavailableNot checked: the service answers400; 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 entry400 INVALID_QUERY, the same entry
The live service no longer has the operationClientError 400 INVALID_QUERY, UNKNOWN_OPERATION on the entry404 NOT_FOUND, after your guards, before any call
The live service changed it so that the build no longer fitsFollows the live service500, logged, after your guards, before any call
An action the client does not listActionNotFoundError, before any callNo 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.errors on the form by path, and the rest in a banner — don't show only error.message.
  • Treat a 401 of the browser client as "sign in again" — it is what an expired session with the service looks like.
  • Treat a 502 STORE_FAILED of 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 503 SERIALIZATION_FAILURE and after params.retryAfter on 429 — don't retry a 502 in a loop.
  • Read failed of an action's summary on several rows — a run whose rows go out each on its own succeeds when one of them ran.

See also ​

SAP, SAP S/4HANA, SAP Fiori, SAPUI5, SAP BTP and other SAP products and services mentioned herein, as well as their respective logos, are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. Atscript OData is an independent open-source project and is not affiliated with, sponsored or endorsed by SAP SE.
Released under the MIT License.