import { MetaplexError, } from './MetaplexError';
/** @group Errors */
export class RpcError extends MetaplexError {
    constructor(input) {
        super(Object.assign(Object.assign({}, input), { key: `rpc.${input.key}`, source: 'rpc' }));
    }
}
/** @group Errors */
export class FailedToSendTransactionError extends RpcError {
    constructor(cause, options) {
        super({
            key: 'failed_to_send_transaction',
            title: 'Failed to Send Transaction',
            problem: `The transaction could not be sent successfully to the network.`,
            solution: 'Check the error below for more information.',
            options: Object.assign(Object.assign({}, options), { logs: cause.logs, cause }),
        });
    }
    asSendTransactionError() {
        return this.cause;
    }
    get error() {
        return this.asSendTransactionError().message;
    }
    get errorLogs() {
        var _a;
        return (_a = this.asSendTransactionError().logs) !== null && _a !== void 0 ? _a : [];
    }
}
/** @group Errors */
export class FailedToConfirmTransactionError extends RpcError {
    constructor(cause, options) {
        super({
            key: 'failed_to_confirm_transaction',
            title: 'Failed to Confirm Transaction',
            problem: `The transaction could not be confirmed.`,
            solution: 'Check the error below for more information.',
            options: Object.assign(Object.assign({}, options), { cause }),
        });
    }
}
/** @group Errors */
export class FailedToConfirmTransactionWithResponseError extends FailedToConfirmTransactionError {
    constructor(response) {
        const getMessage = (error) => {
            if (!error)
                return 'Unknown error';
            if (typeof error === 'string')
                return error;
            try {
                return JSON.stringify(error);
            }
            catch (error) {
                return 'Unknown error';
            }
        };
        super(new Error(getMessage(response.value.err)));
        this.response = response;
    }
    get error() {
        var _a;
        return (_a = this.response.value.err) !== null && _a !== void 0 ? _a : 'Unknown error';
    }
}
//# sourceMappingURL=RpcError.js.map