Each basic operation (e.g. lending and renting) made in Stash Renting SDK is performed through single functions that take two callback arguments for success and failure cases. The success callback returns an object of type StashResponse, whereas the failure callback returns a StashError object. Through that, it gets much more easier to track down various failure cases and to adapt the UI state or the UX flow based on the outcomes of the operations.

StashResponse has the following declaration:

class StashResponse {
    transactions: StashTransaction[];
    args: { [key: string]: any };

    constructor(_transactions: StashTransaction[] = [], _args: {} = {}) {
        this.transactions = _transactions;
        this.args = _args;
    }
};

StashTransaction offers a way to store each transaction hash alongside with the respective receiver (e.g. in payout operations):

class StashTransaction {
    txn_hash: String = "";
    receiver: String | null;

    constructor(_txn_hash: String, _receiver: String | null = null) {
        this.txn_hash = _txn_hash;
        this.receiver = _receiver;
    }
};

Specifically for failure cases, the response is in form of StashError, which is an extension of StashResponse:

class StashError {
    transactions: StashTransaction[];
    message: String = "";
    code: number = -1;
    args: { [key: string]: any };

    constructor(_message: String, _code: number, _transactions: StashTransaction[] = [], _args: {} = {}) {
        this.message = _message;
        this.code = _code;
        this.transactions = _transactions;
        this.args = _args;
    }
};

🚧

Predefined Error Codes and Messages

Please check Error Codes to see the list of all the predefined error cases along with their respective message, code and description.