aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/errors.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-10-19 02:43:36 -0300
committerSebastian <sebasjm@gmail.com>2023-10-19 02:56:14 -0300
commitc6968c3c21d70bd76ce50f232650d183fa8cfa6e (patch)
tree69b7de2c221e1af899dfd2ddc572aafe9fb4f8f8 /packages/taler-util/src/errors.ts
parent39ba26c7623a380c15bf183d25ec8f1fd60b65b6 (diff)
downloadwallet-core-c6968c3c21d70bd76ce50f232650d183fa8cfa6e.tar.xz
talerhttperror definition, for error in http request
Diffstat (limited to 'packages/taler-util/src/errors.ts')
-rw-r--r--packages/taler-util/src/errors.ts33
1 files changed, 19 insertions, 14 deletions
diff --git a/packages/taler-util/src/errors.ts b/packages/taler-util/src/errors.ts
index dcdf56c39..f17f7db6a 100644
--- a/packages/taler-util/src/errors.ts
+++ b/packages/taler-util/src/errors.ts
@@ -34,19 +34,6 @@ import {
type empty = Record<string, never>;
-export interface HttpErrors {
- // timeout
- [TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT]: empty;
- // throttled
- [TalerErrorCode.WALLET_HTTP_REQUEST_THROTTLED]: empty;
- // parsing
- [TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE]: empty;
- // network
- [TalerErrorCode.WALLET_NETWORK_ERROR]: empty;
- // everything else
- [TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR]: empty;
-}
-
export interface DetailsMap {
[TalerErrorCode.WALLET_PENDING_OPERATION_FAILED]: {
innerError: TalerErrorDetail;
@@ -102,7 +89,11 @@ export interface DetailsMap {
requestMethod: string;
throttleStats: Record<string, unknown>;
};
- [TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT]: empty;
+ [TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT]: {
+ requestUrl: string;
+ requestMethod: string;
+ timeoutMs: number;
+ };
[TalerErrorCode.WALLET_NETWORK_ERROR]: {
requestUrl: string;
requestMethod: string;
@@ -205,6 +196,19 @@ export class TalerProtocolViolationError extends Error {
}
}
+// compute a subset of TalerError, just for http request
+type HttpErrors = TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT
+ | TalerErrorCode.WALLET_HTTP_REQUEST_THROTTLED
+ | TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE
+ | TalerErrorCode.WALLET_NETWORK_ERROR
+ | TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR;
+
+type TalerHttpErrorsDetails = {
+ [code in HttpErrors]: TalerError<DetailsMap[code]>
+}
+
+export type TalerHttpError = TalerHttpErrorsDetails[keyof TalerHttpErrorsDetails]
+
export class TalerError<T = any> extends Error {
errorDetail: TalerErrorDetail & T;
private constructor(d: TalerErrorDetail & T) {
@@ -239,6 +243,7 @@ export class TalerError<T = any> extends Error {
): this is TalerError<DetailsMap[C]> {
return this.errorDetail.code === code;
}
+
}
/**