aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/http.ts22
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> {