diff --git a/README.md b/README.md index 8be95a5..6a94f2b 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ try { } ``` -A write certainly was not stored, and throws the error itself, only if its request never went out, for example since the client SDK refused to send it and threw an `IncompatibleServerError`, or could not establish a connection, or since the write was aborted or stalled while connecting, or if the server refused the write before storing anything. A request counts as gone out once its headers have been sent. Through the v2 API, the server refuses a write with every error that it describes in its answer, except one with the code `ErrorCode.storeFailed`, and with the HTTP status `400`, `401`, `408`, `413`, `429`, or `503`. Through the v1 API, it refuses a write with an HTTP status of `4xx`, `503`, or `507`. A write that the server refuses with the HTTP status `429` may be sent again after `retryAfter` seconds. +A write certainly was not stored, and throws the error itself, only if its request never went out, for example since the client SDK refused to send it and threw an `IncompatibleServerError`, or could not establish a connection, or since the write was aborted or stalled while connecting, or if the server refused the write before storing anything. A request counts as gone out once its headers have been sent. Through the v2 API, the server refuses a write with every error that it describes in its answer and with the HTTP status `400`, `401`, `408`, `413`, `429`, or `503`. Through the v1 API, it refuses a write with an HTTP status of `4xx`, `503`, or `507`. A write that the server refuses with the HTTP status `429` may be sent again after `retryAfter` seconds. ### Writing Events diff --git a/src/OutcomeUnknownError.test.ts b/src/OutcomeUnknownError.test.ts index cfd1019..b85cf71 100644 --- a/src/OutcomeUnknownError.test.ts +++ b/src/OutcomeUnknownError.test.ts @@ -88,6 +88,7 @@ const refusals: Record = { ErrorCode.preconditionViolated, ErrorCode.eventSchemaAlreadyRegistered, ErrorCode.storeReadOnly, + ErrorCode.storeFailed, ].map( (code): Case => ({ name: `an error item with the code '${code}'`, @@ -132,15 +133,6 @@ const unknownOutcomes: Record = { isCause: isDbApiErrorWithStatus(status), }), ), - { - name: `an error item with the code '${ErrorCode.storeFailed}'`, - answer: (response: ServerResponse): void => { - writeHead(response, 200, ndJson); - response.end(`${getErrorItem(ErrorCode.storeFailed)}${lines.v2.end}`); - }, - isCause: (error: unknown): boolean => - error instanceof DbApiError && error.code === ErrorCode.storeFailed, - }, { name: 'a stream that ends without its end item', answer: (response: ServerResponse): void => { diff --git a/src/v2/isV2Refusal.ts b/src/v2/isV2Refusal.ts index f44f420..ce78a03 100644 --- a/src/v2/isV2Refusal.ts +++ b/src/v2/isV2Refusal.ts @@ -1,17 +1,16 @@ import type { DbApiError } from '../DbApiError.js'; -import { ErrorCode } from '../ErrorCode.js'; // The statuses with which the v2 API refuses a request before handling it. const refusingStatuses = new Set([400, 401, 408, 413, 429, 503]); // Tells whether the v2 API refused a write before storing anything. It does so -// with every error item, except for a failed store, and with some statuses. -const isV2Refusal = (error: DbApiError): boolean => { - if (error.status === 200) { - return error.code !== ErrorCode.storeFailed; - } - - return refusingStatuses.has(error.status); -}; +// with every error item, which comes at the status 200, and with some statuses. +// This includes an error item with the code store-failed, which the server +// sends for every write after its store has failed, since it then refuses +// writes until it is restarted. The write during which storing fails gets the +// status 500 or a stream without its end item instead, so its outcome stays +// unknown. +const isV2Refusal = (error: DbApiError): boolean => + error.status === 200 || refusingStatuses.has(error.status); export { isV2Refusal };