Close endpoint failure types across service and web boundaries
This commit is contained in:
parent
fb94ea2c23
commit
390434bed1
1 changed files with 266 additions and 72 deletions
|
|
@ -10,6 +10,7 @@ import {
|
|||
type DeleteBatchResponse,
|
||||
type DeleteEndpointRequest,
|
||||
type DeleteFailureCode,
|
||||
type DeleteItemFailure,
|
||||
type DeleteItemResponse,
|
||||
type DeletePlanEndpointRequest,
|
||||
type DeletePlanFailureCode,
|
||||
|
|
@ -457,12 +458,32 @@ function decodeDeleteBatchResponse(value: unknown): DeleteBatchResponse {
|
|||
|
||||
function decodeDeleteItemResponse(value: unknown): DeleteItemResponse {
|
||||
const object = record(value, 'delete item response');
|
||||
return {
|
||||
path: stringField(object, 'path'),
|
||||
operation_id: stringField(object, 'operation_id'),
|
||||
result: nullableMutationResultField(object, 'result'),
|
||||
error: nullableStringField(object, 'error')
|
||||
};
|
||||
const path = stringField(object, 'path');
|
||||
const operation_id = stringField(object, 'operation_id');
|
||||
const result = nullableMutationResultField(object, 'result');
|
||||
const error = nullableDeleteItemFailureField(object, 'error');
|
||||
if (result !== null && error === null) {
|
||||
return { path, operation_id, result, error };
|
||||
}
|
||||
if (result === null && error !== null) {
|
||||
return { path, operation_id, result, error };
|
||||
}
|
||||
throw new TypeError('delete item response must contain exactly one outcome');
|
||||
}
|
||||
|
||||
function nullableDeleteItemFailureField(
|
||||
object: Record<string, unknown>,
|
||||
field: string
|
||||
): DeleteItemFailure | null {
|
||||
const value = object[field];
|
||||
if (
|
||||
value === null ||
|
||||
value === 'database_unavailable' ||
|
||||
value === 'object_store_unavailable'
|
||||
) {
|
||||
return value;
|
||||
}
|
||||
throw new TypeError(`${field} must be a declared delete item failure or null`);
|
||||
}
|
||||
|
||||
function record(value: unknown, label: string): Record<string, unknown> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue