From ef520a0b4fe7d2ebba8beaba0806dbfc499c4e37 Mon Sep 17 00:00:00 2001 From: mhh Date: Mon, 4 Dec 2023 10:34:42 +0100 Subject: [PATCH] Update InsufficientFundsError to have `required_balance` and `account_balance` fields --- src/aleph/sdk/client/authenticated_http.py | 2 +- src/aleph/sdk/exceptions.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/aleph/sdk/client/authenticated_http.py b/src/aleph/sdk/client/authenticated_http.py index 4b0c9443..78b006fd 100644 --- a/src/aleph/sdk/client/authenticated_http.py +++ b/src/aleph/sdk/client/authenticated_http.py @@ -583,7 +583,7 @@ async def create_instance( account_balance = float(error["account_balance"]) required_balance = float(error["required_balance"]) raise InsufficientFundsError( - f"Account balance {account_balance} is not enough to create instance, required {required_balance}" + required_funds=required_balance, available_funds=account_balance ) else: raise ValueError(f"Unknown error code {error_code}: {rejected_message}") diff --git a/src/aleph/sdk/exceptions.py b/src/aleph/sdk/exceptions.py index 158d6911..39972f7f 100644 --- a/src/aleph/sdk/exceptions.py +++ b/src/aleph/sdk/exceptions.py @@ -69,4 +69,12 @@ class ForgottenMessageError(QueryError): class InsufficientFundsError(Exception): """Raised when the account does not have enough funds to perform an action""" - pass + required_funds: float + available_funds: float + + def __init__(self, required_funds: float, available_funds: float): + self.required_funds = required_funds + self.available_funds = available_funds + super().__init__( + f"Insufficient funds: required {required_funds}, available {available_funds}" + )