function isError<K, T>(error, code): error is T

Returns true if the error matches an error thrown by quais that matches the error code.

In TypeScript environments, this can be used to check that error matches an quaisError type, which means the expected properties will be set.

Type parameters

Type parameter
K extends ErrorCode
T extends
| UnknownError
| InvalidArgumentError
| BadDataError
| NotImplementedError
| UnsupportedOperationError
| NetworkError
| ServerError
| TimeoutError
| CancelledError
| BufferOverrunError
| NumericFaultError
| MissingArgumentError
| UnexpectedArgumentError
| CallExceptionError
| InsufficientFundsError
| NonceExpiredError
| ReplacementUnderpricedError
| TransactionReplacedError
| TransactionNotFoundError
| TransactionAlreadyKnown
| ActionRejectedError
| ProviderFailedToInitializeError

Parameters

ParameterType
errorany
codeK

Returns

error is T

Example

try {
    // code....
} catch (e) {
    if (isError(e, 'CALL_EXCEPTION')) {
        // The Type Guard has validated this object
        console.log(e.data);
    }
}

See

ErrorCodes

Source

utils/errors.ts:664