diff options
author | Florian Dold <florian@dold.me> | 2021-08-24 14:25:46 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-08-24 14:30:33 +0200 |
commit | 408d8e9fc896193fbcff1afd12aa04ab6d513798 (patch) | |
tree | a117a3c5d9130ea9b18c4198d3978f38dbd2f101 /packages/taler-wallet-core/src/util | |
parent | 7553ae7c74bc04c268b77d010fb2f5b5eacad460 (diff) | |
download | wallet-core-408d8e9fc896193fbcff1afd12aa04ab6d513798.tar.xz |
towards handling frozen refreshes
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r-- | packages/taler-wallet-core/src/util/http.ts | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/packages/taler-wallet-core/src/util/http.ts b/packages/taler-wallet-core/src/util/http.ts index 68a63e124..ce507465a 100644 --- a/packages/taler-wallet-core/src/util/http.ts +++ b/packages/taler-wallet-core/src/util/http.ts @@ -24,10 +24,7 @@ /** * Imports */ -import { - OperationFailedError, - makeErrorDetails, -} from "../errors.js"; +import { OperationFailedError, makeErrorDetails } from "../errors.js"; import { Logger, Duration, @@ -68,6 +65,7 @@ export enum HttpResponseStatus { Gone = 210, NotModified = 304, PaymentRequired = 402, + NotFound = 404, Conflict = 409, } @@ -158,6 +156,33 @@ export async function readTalerErrorResponse( return errJson; } +export async function readUnexpectedResponseDetails( + httpResponse: HttpResponse, +): Promise<TalerErrorDetails> { + const errJson = await httpResponse.json(); + const talerErrorCode = errJson.code; + if (typeof talerErrorCode !== "number") { + return makeErrorDetails( + TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, + "Error response did not contain error code", + { + requestUrl: httpResponse.requestUrl, + requestMethod: httpResponse.requestMethod, + httpStatusCode: httpResponse.status, + }, + ); + } + return makeErrorDetails( + TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR, + "Unexpected error code in response", + { + requestUrl: httpResponse.requestUrl, + httpStatusCode: httpResponse.status, + errorResponse: errJson, + }, + ); +} + export async function readSuccessResponseJsonOrErrorCode<T>( httpResponse: HttpResponse, codec: Codec<T>, |