Exceptions

Exception classes for P2P, Wallet and NGNT

On the request level, the HTTPError exception when caught in the except block is raised by one of the built-in custom exception classes.

These built-in custom classes help the developer to understand the source of the error. The built-in custom classes are:

  • ServerError

  • AccountError

  • ClientError

  • WalletError

  • QueryError

  • P2PError

The custom classes are built with this template:

class ClassError(Exception):
    def __init__(self, *args):
        if args:
            self.message = args[0]
            self.status_code = args[1]
        else:
            self.message = None
            self.status_code = 404

    @property
    def response(self):
        return {
            "status": "error",
            "name": "ClassError",
            "code": self.status_code,
            "message": self.message
        }

where ClassError is one of the available exception classes in the library.

Example

To return the appropriate error response for an invalid query, the library executes this block of code:

Last updated

Was this helpful?