commit c9c6425f9fe3e8d7beb1f6455906812000a42d4a
parent d52c21396fbd480d29c075cb4b6f63645dfe8a68
Author: Sebastian <sebasjm@gmail.com>
Date: Thu, 11 Jul 2024 12:05:04 -0300
remove some any types
Diffstat:
3 files changed, 51 insertions(+), 19 deletions(-)
diff --git a/packages/taler-util/src/http-client/officer-account.ts b/packages/taler-util/src/http-client/officer-account.ts
@@ -50,8 +50,8 @@ export async function unlockOfficerAccount(
rawKey,
rawPassword,
password,
- ).catch((e: Error) => {
- throw new UnwrapKeyError(e.message);
+ ).catch((e) => {
+ throw new UnwrapKeyError(e instanceof Error ? e.message : String(e));
})) as SigningKey;
const publicKey = eddsaGetPublic(signingKey);
diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts
@@ -147,7 +147,7 @@ export async function readTalerErrorResponse(
let errJson;
try {
errJson = await httpResponse.json();
- } catch (e: any) {
+ } catch (e) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
{
@@ -155,7 +155,7 @@ export async function readTalerErrorResponse(
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
response: await httpResponse.text(),
- validationError: e.toString(),
+ validationError: e instanceof Error ? e.message : String(e),
},
"Couldn't parse JSON format from error response",
);
@@ -188,7 +188,7 @@ export async function readUnexpectedResponseDetails(
let errJson;
try {
errJson = await httpResponse.json();
- } catch (e: any) {
+ } catch (e) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
{
@@ -196,7 +196,7 @@ export async function readUnexpectedResponseDetails(
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
response: await httpResponse.text(),
- validationError: e.toString(),
+ validationError: e instanceof Error ? e.message : String(e),
},
"Couldn't parse JSON format from error response",
);
@@ -239,7 +239,7 @@ export async function readSuccessResponseJsonOrErrorCode<T>(
let respJson;
try {
respJson = await httpResponse.json();
- } catch (e: any) {
+ } catch (e) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
{
@@ -247,7 +247,7 @@ export async function readSuccessResponseJsonOrErrorCode<T>(
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
response: await httpResponse.text(),
- validationError: e.toString(),
+ validationError: e instanceof Error ? e.message : String(e),
},
"Couldn't parse JSON format from response",
);
@@ -255,7 +255,7 @@ export async function readSuccessResponseJsonOrErrorCode<T>(
let parsedResponse: T;
try {
parsedResponse = codec.decode(respJson);
- } catch (e: any) {
+ } catch (e) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
{
@@ -263,7 +263,7 @@ export async function readSuccessResponseJsonOrErrorCode<T>(
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
response: await httpResponse.text(),
- validationError: e.toString(),
+ validationError: e instanceof Error ? e.message : String(e),
},
"Response invalid",
);
@@ -281,7 +281,7 @@ export async function readResponseJsonOrErrorCode<T>(
let respJson;
try {
respJson = await httpResponse.json();
- } catch (e: any) {
+ } catch (e) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
{
@@ -289,7 +289,7 @@ export async function readResponseJsonOrErrorCode<T>(
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
response: await httpResponse.text(),
- validationError: e.toString(),
+ validationError: e instanceof Error ? e.message : String(e),
},
"Couldn't parse JSON format from response",
);
@@ -297,7 +297,7 @@ export async function readResponseJsonOrErrorCode<T>(
let parsedResponse: T;
try {
parsedResponse = codec.decode(respJson);
- } catch (e: any) {
+ } catch (e) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
{
@@ -305,7 +305,7 @@ export async function readResponseJsonOrErrorCode<T>(
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
response: await httpResponse.text(),
- validationError: e.toString(),
+ validationError: e instanceof Error ? e.message : String(e),
},
"Response invalid",
);
@@ -377,7 +377,7 @@ export async function readSuccessResponseTextOrErrorCode<T>(
let errJson;
try {
errJson = await httpResponse.json();
- } catch (e: any) {
+ } catch (e) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
{
@@ -385,7 +385,7 @@ export async function readSuccessResponseTextOrErrorCode<T>(
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
response: await httpResponse.text(),
- validationError: e.toString(),
+ validationError: e instanceof Error ? e.message : String(e),
},
"Couldn't parse JSON format from error response",
);
@@ -423,7 +423,7 @@ export async function checkSuccessResponseOrThrow(
let errJson;
try {
errJson = await httpResponse.json();
- } catch (e: any) {
+ } catch (e) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
{
@@ -431,7 +431,7 @@ export async function checkSuccessResponseOrThrow(
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
response: await httpResponse.text(),
- validationError: e.toString(),
+ validationError: e instanceof Error ? e.message : String(e),
},
"Couldn't parse JSON format from error response",
);
@@ -496,7 +496,7 @@ export interface HttpLibArgs {
printAsCurl?: boolean;
}
-export function encodeBody(body: any): ArrayBuffer {
+export function encodeBody(body: unknown): ArrayBuffer {
if (body == null) {
return new ArrayBuffer(0);
}
diff --git a/packages/taler-util/src/type-override.d.ts b/packages/taler-util/src/type-override.d.ts
@@ -0,0 +1,32 @@
+/*
+ This file is part of GNU Taler
+ (C) 2021-2024 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+ * define unkown type of catch function
+ */
+interface Promise<T> {
+ /**
+ * Attaches a callback for only the rejection of the Promise.
+ * @param onrejected The callback to execute when the Promise is rejected.
+ * @returns A Promise for the completion of the callback.
+ */
+ catch<TResult = never>(
+ onrejected?:
+ | ((reason: unknown) => TResult | PromiseLike<TResult>)
+ | undefined
+ | null,
+ ): Promise<T | TResult>;
+}