diff options
author | Sebastian <sebasjm@gmail.com> | 2024-01-09 18:51:49 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-01-09 18:51:49 -0300 |
commit | f5771cc7b99dc938fd606dcbee350b66ec8027c9 (patch) | |
tree | 95c1aa5b8a5e6067c7689b0caf161c50d1f694ed /packages/taler-util/src/operation.ts | |
parent | 1826b9121a0308aa0a7ac39a89ad7dc8ea2ae965 (diff) | |
download | wallet-core-f5771cc7b99dc938fd606dcbee350b66ec8027c9.tar.xz |
prepare for 2fa impl
Diffstat (limited to 'packages/taler-util/src/operation.ts')
-rw-r--r-- | packages/taler-util/src/operation.ts | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/packages/taler-util/src/operation.ts b/packages/taler-util/src/operation.ts index 06bfe26bd..8b264d905 100644 --- a/packages/taler-util/src/operation.ts +++ b/packages/taler-util/src/operation.ts @@ -1,5 +1,5 @@ import { HttpResponse, readSuccessResponseJsonOrThrow, readTalerErrorResponse } from "./http-common.js"; -import { Codec, TalerError, TalerErrorCode, TalerErrorDetail } from "./index.js"; +import { Codec, HttpStatusCode, TalerError, TalerErrorCode, TalerErrorDetail } from "./index.js"; export type OperationResult<Body, ErrorEnum> = | OperationOk<Body> @@ -31,6 +31,14 @@ export function opFixedSuccess<T>(body: T): OperationOk<T> { export function opEmptySuccess(): OperationOk<void> { return { type: "ok" as const, body: void 0 } } +export async function opKnownHttpFailure<T extends HttpStatusCode>(s: T, resp: HttpResponse): Promise<OperationFail<T>> { + const detail = await readTalerErrorResponse(resp) + return { type: "fail", case: s, detail } +} +export async function opKnownTalerFailure<T extends TalerErrorCode>(s: T, resp: HttpResponse): Promise<OperationFail<T>> { + const detail = await readTalerErrorResponse(resp) + return { type: "fail", case: s, detail } +} export async function opKnownFailure<T extends string>(s: T, resp: HttpResponse): Promise<OperationFail<T>> { const detail = await readTalerErrorResponse(resp) return { type: "fail", case: s, detail } |