Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 1 addition & 9 deletions src/OutcomeUnknownError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const refusals: Record<ApiVersion, Case[]> = {
ErrorCode.preconditionViolated,
ErrorCode.eventSchemaAlreadyRegistered,
ErrorCode.storeReadOnly,
ErrorCode.storeFailed,
].map(
(code): Case => ({
name: `an error item with the code '${code}'`,
Expand Down Expand Up @@ -132,15 +133,6 @@ const unknownOutcomes: Record<ApiVersion, Case[]> = {
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 => {
Expand Down
17 changes: 8 additions & 9 deletions src/v2/isV2Refusal.ts
Original file line number Diff line number Diff line change
@@ -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 };
Loading