From eeea3e62a01638b37c8bb8d6f8fdeac129a4afae Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 17 Jan 2023 15:58:20 -0300 Subject: stronger type check to be sure that ErrorDetails is consistent --- packages/taler-wallet-core/src/util/http.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'packages/taler-wallet-core/src/util') diff --git a/packages/taler-wallet-core/src/util/http.ts b/packages/taler-wallet-core/src/util/http.ts index 118da40fe..1da31a315 100644 --- a/packages/taler-wallet-core/src/util/http.ts +++ b/packages/taler-wallet-core/src/util/http.ts @@ -68,7 +68,7 @@ export interface HttpRequestOptions { */ cancellationToken?: CancellationToken; - body?: string | ArrayBuffer | Object; + body?: string | ArrayBuffer | Record; } /** @@ -185,6 +185,7 @@ export async function readUnexpectedResponseDetails( TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR, { requestUrl: httpResponse.requestUrl, + requestMethod: httpResponse.requestMethod, httpStatusCode: httpResponse.status, errorResponse: errJson, }, @@ -211,6 +212,7 @@ export async function readSuccessResponseJsonOrErrorCode( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, { requestUrl: httpResponse.requestUrl, + requestMethod: httpResponse.requestMethod, httpStatusCode: httpResponse.status, validationError: e.toString(), }, @@ -223,11 +225,18 @@ export async function readSuccessResponseJsonOrErrorCode( }; } +type HttpErrorDetails = { + requestUrl: string; + requestMethod: string; + httpStatusCode: number; +}; + export function getHttpResponseErrorDetails( httpResponse: HttpResponse, -): Record { +): HttpErrorDetails { return { requestUrl: httpResponse.requestUrl, + requestMethod: httpResponse.requestMethod, httpStatusCode: httpResponse.status, }; } @@ -240,6 +249,7 @@ export function throwUnexpectedRequestError( TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR, { requestUrl: httpResponse.requestUrl, + requestMethod: httpResponse.requestMethod, httpStatusCode: httpResponse.status, errorResponse: talerErrorResponse, }, -- cgit v1.2.3