lib/errors.js

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.NotFoundError = exports.NetworkError = exports.BadResponseError = exports.BadRequestError = exports.AccountRequiresMemoError = void 0;
// For ES5 compatibility (https://stackoverflow.com/a/55066280).
/* tslint:disable:variable-name max-classes-per-file */

class NetworkError extends Error {
  constructor(message, response) {
    const trueProto = new.target.prototype;
    super(message);
    this.__proto__ = trueProto;
    this.constructor = NetworkError;
    this.response = response;
  }
  getResponse() {
    return this.response;
  }
}
exports.NetworkError = NetworkError;
class NotFoundError extends NetworkError {
  constructor(message, response) {
    const trueProto = new.target.prototype;
    super(message, response);
    this.__proto__ = trueProto;
    this.constructor = NotFoundError;
    this.name = "NotFoundError";
  }
}
exports.NotFoundError = NotFoundError;
class BadRequestError extends NetworkError {
  constructor(message, response) {
    const trueProto = new.target.prototype;
    super(message, response);
    this.__proto__ = trueProto;
    this.constructor = BadRequestError;
    this.name = "BadRequestError";
  }
}
exports.BadRequestError = BadRequestError;
class BadResponseError extends NetworkError {
  constructor(message, response) {
    const trueProto = new.target.prototype;
    super(message, response);
    this.__proto__ = trueProto;
    this.constructor = BadResponseError;
    this.name = "BadResponseError";
  }
}

/**
 * AccountRequiresMemoError is raised when a transaction is trying to submit an
 * operation to an account which requires a memo. See
 * [SEP0029](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0029.md)
 * for more information.
 *
 * This error contains two attributes to help you identify the account requiring
 * the memo and the operation where the account is the destination
 *
 * ```
 * console.log('The following account requires a memo ', err.accountId)
 * console.log('The account is used in operation: ', err.operationIndex)
 * ```
 *
 */
exports.BadResponseError = BadResponseError;
class AccountRequiresMemoError extends Error {
  /**
   * accountId account which requires a memo.
   */

  /**
   * operationIndex operation where accountId is the destination.
   */

  /**
   * Create an AccountRequiresMemoError
   * @param {message} message - error message
   * @param {string} accountId - The account which requires a memo.
   * @param {number} operationIndex - The index of the operation where `accountId` is the destination.
   */
  constructor(message, accountId, operationIndex) {
    const trueProto = new.target.prototype;
    super(message);
    this.__proto__ = trueProto;
    this.constructor = AccountRequiresMemoError;
    this.name = "AccountRequiresMemoError";
    this.accountId = accountId;
    this.operationIndex = operationIndex;
  }
}
exports.AccountRequiresMemoError = AccountRequiresMemoError;