diff options
author | Florian Dold <florian@dold.me> | 2022-03-22 21:16:38 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-03-22 21:16:38 +0100 |
commit | 5d23eb36354d07508a015531f298b3e261bbafce (patch) | |
tree | fae0d2599c94d88c9264bb63a301adb1706824c1 /packages/taler-util/src | |
parent | f8d12f7b0d4af1b1769b89e80c87f9c169678564 (diff) |
wallet: improve error handling and error codes
Diffstat (limited to 'packages/taler-util/src')
-rw-r--r-- | packages/taler-util/src/notifications.ts | 26 | ||||
-rw-r--r-- | packages/taler-util/src/taler-error-codes.ts | 70 | ||||
-rw-r--r-- | packages/taler-util/src/transactionsTypes.ts | 4 | ||||
-rw-r--r-- | packages/taler-util/src/walletTypes.ts | 14 |
4 files changed, 90 insertions, 24 deletions
diff --git a/packages/taler-util/src/notifications.ts b/packages/taler-util/src/notifications.ts index e8f27062c..b3d9ad1dc 100644 --- a/packages/taler-util/src/notifications.ts +++ b/packages/taler-util/src/notifications.ts @@ -22,7 +22,7 @@ /** * Imports. */ -import { TalerErrorDetails } from "./walletTypes.js"; +import { TalerErrorDetail } from "./walletTypes.js"; export enum NotificationType { CoinWithdrawn = "coin-withdrawn", @@ -157,62 +157,62 @@ export interface ExchangeAddedNotification { export interface ExchangeOperationErrorNotification { type: NotificationType.ExchangeOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface RefreshOperationErrorNotification { type: NotificationType.RefreshOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface BackupOperationErrorNotification { type: NotificationType.BackupOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface RefundStatusOperationErrorNotification { type: NotificationType.RefundStatusOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface RefundApplyOperationErrorNotification { type: NotificationType.RefundApplyOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface PayOperationErrorNotification { type: NotificationType.PayOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface ProposalOperationErrorNotification { type: NotificationType.ProposalOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface TipOperationErrorNotification { type: NotificationType.TipOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface WithdrawOperationErrorNotification { type: NotificationType.WithdrawOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface RecoupOperationErrorNotification { type: NotificationType.RecoupOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface DepositOperationErrorNotification { type: NotificationType.DepositOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface ReserveOperationErrorNotification { type: NotificationType.ReserveOperationError; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface ReserveCreatedNotification { diff --git a/packages/taler-util/src/taler-error-codes.ts b/packages/taler-util/src/taler-error-codes.ts index b22f29a19..8ea97f7e7 100644 --- a/packages/taler-util/src/taler-error-codes.ts +++ b/packages/taler-util/src/taler-error-codes.ts @@ -22,6 +22,8 @@ */ export enum TalerErrorCode { + + /** * Special code to indicate success (no error). * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). @@ -79,6 +81,13 @@ export enum TalerErrorCode { GENERIC_CONFIGURATION_INVALID = 14, /** + * The client made a request to a service, but received an error response it does not know how to handle. + * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). + * (A value of 0 indicates that the error is generated client-side). + */ + GENERIC_UNEXPECTED_REQUEST_ERROR = 15, + + /** * The HTTP method used is invalid for this endpoint. * Returned with an HTTP status code of #MHD_HTTP_METHOD_NOT_ALLOWED (405). * (A value of 0 indicates that the error is generated client-side). @@ -373,6 +382,20 @@ export enum TalerErrorCode { EXCHANGE_GENERIC_NEW_DENOMS_ARRAY_SIZE_EXCESSIVE = 1018, /** + * The reserve public key was malformed. + * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400). + * (A value of 0 indicates that the error is generated client-side). + */ + EXCHANGE_GENERIC_RESERVE_PUB_MALFORMED = 1019, + + /** + * The time at the server is too far off from the time specified in the request. Most likely the client system time is wrong. + * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400). + * (A value of 0 indicates that the error is generated client-side). + */ + EXCHANGE_GENERIC_CLOCK_SKEW = 1020, + + /** * The exchange did not find information about the specified transaction in the database. * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404). * (A value of 0 indicates that the error is generated client-side). @@ -541,11 +564,25 @@ export enum TalerErrorCode { EXCHANGE_DEPOSIT_FEE_ABOVE_AMOUNT = 1222, /** - * The reserve status was requested using a unknown key. + * The reserve balance, status or history was requested for a reserve which is not known to the exchange. * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404). * (A value of 0 indicates that the error is generated client-side). */ - EXCHANGE_RESERVES_GET_STATUS_UNKNOWN = 1250, + EXCHANGE_RESERVES_STATUS_UNKNOWN = 1250, + + /** + * The reserve status was requested with a bad signature. + * Returned with an HTTP status code of #MHD_HTTP_FORBIDDEN (403). + * (A value of 0 indicates that the error is generated client-side). + */ + EXCHANGE_RESERVES_STATUS_BAD_SIGNATURE = 1251, + + /** + * The reserve history was requested with a bad signature. + * Returned with an HTTP status code of #MHD_HTTP_FORBIDDEN (403). + * (A value of 0 indicates that the error is generated client-side). + */ + EXCHANGE_RESERVES_HISTORY_BAD_SIGNATURE = 1252, /** * The exchange encountered melt fees exceeding the melted coin's contribution. @@ -1395,6 +1432,27 @@ export enum TalerErrorCode { MERCHANT_POST_ORDERS_ID_PAY_EXCHANGE_FAILED = 2170, /** + * The payment required a minimum age but one of the coins (of a denomination with support for age restriction) did not provide any age_commitment. + * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400). + * (A value of 0 indicates that the error is generated client-side). + */ + MERCHANT_POST_ORDERS_ID_PAY_AGE_COMMITMENT_MISSING = 2171, + + /** + * The payment required a minimum age but one of the coins provided an age_commitment that contained a wrong number of public keys compared to the number of age groups defined in the denomination of the coin. + * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400). + * (A value of 0 indicates that the error is generated client-side). + */ + MERCHANT_POST_ORDERS_ID_PAY_AGE_COMMITMENT_SIZE_MISMATCH = 2172, + + /** + * The payment required a minimum age but one of the coins provided a minimum_age_sig that couldn't be verified with the given age_commitment for that particular minimum age. + * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400). + * (A value of 0 indicates that the error is generated client-side). + */ + MERCHANT_POST_ORDERS_ID_PAY_AGE_VERIFICATION_FAILED = 2173, + + /** * The contract hash does not match the given order ID. * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400). * (A value of 0 indicates that the error is generated client-side). @@ -2151,6 +2209,13 @@ export enum TalerErrorCode { WALLET_CONTRACT_TERMS_MALFORMED = 7020, /** + * A pending operation failed, and thus the request can't be completed. + * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). + * (A value of 0 indicates that the error is generated client-side). + */ + WALLET_PENDING_OPERATION_FAILED = 7021, + + /** * We encountered a timeout with our payment backend. * Returned with an HTTP status code of #MHD_HTTP_GATEWAY_TIMEOUT (504). * (A value of 0 indicates that the error is generated client-side). @@ -2646,4 +2711,5 @@ export enum TalerErrorCode { * (A value of 0 indicates that the error is generated client-side). */ END = 9999, + } diff --git a/packages/taler-util/src/transactionsTypes.ts b/packages/taler-util/src/transactionsTypes.ts index bccbc7737..b9a227b68 100644 --- a/packages/taler-util/src/transactionsTypes.ts +++ b/packages/taler-util/src/transactionsTypes.ts @@ -42,7 +42,7 @@ import { codecForList, codecForAny, } from "./codec.js"; -import { TalerErrorDetails } from "./walletTypes.js"; +import { TalerErrorDetail } from "./walletTypes.js"; export interface TransactionsRequest { /** @@ -92,7 +92,7 @@ export interface TransactionCommon { // Amount added or removed from the wallet's balance (including all fees and other costs) amountEffective: AmountString; - error?: TalerErrorDetails; + error?: TalerErrorDetail; } export type Transaction = diff --git a/packages/taler-util/src/walletTypes.ts b/packages/taler-util/src/walletTypes.ts index 3c4fa96c7..1f88c39ee 100644 --- a/packages/taler-util/src/walletTypes.ts +++ b/packages/taler-util/src/walletTypes.ts @@ -60,6 +60,7 @@ import { import { OrderShortInfo, codecForOrderShortInfo } from "./transactionsTypes.js"; import { BackupRecovery } from "./backupTypes.js"; import { PaytoUri } from "./payto.js"; +import { TalerErrorCode } from "./taler-error-codes.js"; /** * Response for the create reserve request to the wallet. @@ -136,7 +137,7 @@ export interface ConfirmPayResultDone { export interface ConfirmPayResultPending { type: ConfirmPayResultType.Pending; - lastError: TalerErrorDetails | undefined; + lastError: TalerErrorDetail | undefined; } export type ConfirmPayResult = ConfirmPayResultDone | ConfirmPayResultPending; @@ -455,11 +456,10 @@ export interface WalletDiagnostics { dbOutdated: boolean; } -export interface TalerErrorDetails { - code: number; - hint: string; - message: string; - details: unknown; +export interface TalerErrorDetail { + code: TalerErrorCode; + hint?: string; + [x: string]: unknown; } /** @@ -850,7 +850,7 @@ export interface CoreApiResponseError { type: "error"; operation: string; id: string; - error: TalerErrorDetails; + error: TalerErrorDetail; } export interface WithdrawTestBalanceRequest { |