From fd45d189259cef0a3a51683bb12412cd8c6fb9eb Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 15 Feb 2024 16:59:56 -0300 Subject: add exchange key in the http lib and default toString for taler error --- packages/taler-util/src/operation.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'packages/taler-util/src/operation.ts') diff --git a/packages/taler-util/src/operation.ts b/packages/taler-util/src/operation.ts index a554e1f31..02cf70196 100644 --- a/packages/taler-util/src/operation.ts +++ b/packages/taler-util/src/operation.ts @@ -30,10 +30,14 @@ import { TalerErrorDetail, } from "./index.js"; -export type OperationResult = +type OperationFailWithBodyOrNever = + ErrorEnum extends keyof ErrorMap ? OperationFailWithBody : never; + +export type OperationResult = | OperationOk - | OperationAlternative - | OperationFail; + | OperationAlternative + | OperationFail + | OperationFailWithBodyOrNever; export function isOperationOk( c: OperationResult, @@ -89,6 +93,15 @@ export interface OperationAlternative { body: B; } +export interface OperationFailWithBody { + type: "fail"; + + httpResp: HttpResponse; + + case: keyof B; + body: B[OperationFailWithBody["case"]]; +} + export async function opSuccess( resp: HttpResponse, codec: Codec, @@ -109,6 +122,13 @@ export function opEmptySuccess(resp: HttpResponse): OperationOk { return { type: "ok" as const, body: void 0, httpResp: resp }; } +export async function opKnownFailureWithBody( + case_: keyof B, + body: B[typeof case_], +): Promise> { + return { type: "fail", case: case_, body, httpResp: {} as any }; +} + export async function opKnownAlternativeFailure( resp: HttpResponse, s: T, -- cgit v1.2.3