class AppError extends Error {
  constructor(message, code = 'APP_ERROR') {
    super(message);
    this.name = this.constructor.name;
    this.code = code;

    // важно для наследования Error
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, this.constructor);
    }
  }
}

class MaintenanceError extends AppError {
  constructor(message = 'Application is under maintenance') {
    super(message, 'MAINTENANCE');
  }
}

class TelegramInitDataError extends AppError {
  constructor(message = 'Application must be opened inside Telegram') {
    super(message, 'NO_INIT_DATA');
  }
}

export {
  AppError,
  MaintenanceError,
  TelegramInitDataError,
};
