diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-08-01 13:52:08 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-08-01 13:52:46 +0530 |
commit | aa481e42675fb7c4dcbbeec0ba1c61e1953b9596 (patch) | |
tree | b1283f27713b9ff8619773a96b775a263e4aea18 /src/util | |
parent | b37c98346d407c749a5cd971f798428c42b248c3 (diff) |
use wallet's http lib for test balance withdrawal, remove redundant integration tests
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/http.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util/http.ts b/src/util/http.ts index abbc8df03..38892491b 100644 --- a/src/util/http.ts +++ b/src/util/http.ts @@ -300,6 +300,7 @@ export async function readSuccessResponseJsonOrThrow<T>( throwUnexpectedRequestError(httpResponse, r.talerErrorResponse); } + export async function readSuccessResponseTextOrErrorCode<T>( httpResponse: HttpResponse, ): Promise<ResponseOrError<string>> { @@ -329,6 +330,27 @@ export async function readSuccessResponseTextOrErrorCode<T>( }; } +export async function checkSuccessResponseOrThrow( + httpResponse: HttpResponse, +): Promise<void> { + if (!(httpResponse.status >= 200 && httpResponse.status < 300)) { + const errJson = await httpResponse.json(); + const talerErrorCode = errJson.code; + if (typeof talerErrorCode !== "number") { + throw new OperationFailedError( + makeErrorDetails( + TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, + "Error response did not contain error code", + { + requestUrl: httpResponse.requestUrl, + }, + ), + ); + } + throwUnexpectedRequestError(httpResponse, errJson); + } +} + export async function readSuccessResponseTextOrThrow<T>( httpResponse: HttpResponse, ): Promise<string> { |