How to use the meteor/meteor.Meteor.Error function in meteor

To help you get started, we’ve selected a few meteor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reactioncommerce / reaction / server / methods / core / cart.js View on Github external
const selector = {
      _id: cartId
    };

    const update = {
      $set: {
        billing: payments
      }
    };

    try {
      Collections.Cart.update(selector, update);
    } catch (e) {
      Logger.error(e);
      throw new Meteor.Error("server-error", "An error occurred saving the order");
    }

    // Calculate discounts
    Hooks.Events.run("afterCartUpdateCalculateDiscount", cartId);

    // Calculate taxes
    Hooks.Events.run("afterCartUpdateCalculateTaxes", cartId);

    return Collections.Cart.findOne(selector);
  },
github 4minitz / 4minitz / imports / collections / workflow_private.js View on Github external
function checkUserMayLeave(meetingSeriesId) {
    // Make sure the user is logged in before changing collections
    if (!Meteor.userId()) {
        throw new Meteor.Error('not-authorized');
    }

    // Ensure user can not update documents of other users
    let userRoles = new UserRoles(Meteor.userId());
    if (userRoles.isModeratorOf(meetingSeriesId)) {
        throw new Meteor.Error('Cannot leave this meeting series', 'Moderators may only be removed by other moderators.');
    }
    if (! userRoles.isInvitedTo(meetingSeriesId)) {
        throw new Meteor.Error('Cannot leave this meeting series', 'You are not invited to this meeting series.');
    }
}
github ACGN-stock / acgn-stock / server / functions / foundation / doOnFoundationSuccess.js View on Github external
function processStockOffering(investors) {
  let price = calculateInitialPrice(investors);

  let directors;
  let totalRelease;

  do {
    if (price < 1) {
      throw new Meteor.Error('something went wrong: price < 1');
    }

    directors = calculateDirectors(investors, price);

    totalRelease = _.reduce(directors, (sum, directorData) => {
      return sum + directorData.stocks;
    }, 0);

    // 確保股數在最小限制之上,否則股價折半重新計算
    if (totalRelease < minReleaseStock) {
      price = Math.floor(price / 2);
    }
  }
  while (totalRelease < minReleaseStock);

  return { directors, price, totalRelease };
github reactioncommerce / reaction / imports / plugins / core / revisions / server / hooks.js View on Github external
if (productHasAncestors) {
    // Verify there are no deleted ancestors,
    // Variants cannot be restored if their parent product / variant is deleted
    const archivedCount = Revisions.find({
      "documentId": { $in: product.ancestors },
      "documentData.isDeleted": true,
      "workflow.status": {
        $nin: [
          "revision/published"
        ]
      }
    }).count();

    if (archivedCount > 0) {
      Logger.debug(`Cannot create product ${product._id} as a product/variant higher in it's ancestors tree is marked as 'isDeleted'.`);
      throw new Meteor.Error("unable-to-create-variant", "Unable to create product variant");
    }
  }


  if (!productRevision) {
    Logger.debug(`No revision found for product ${product._id}. Creating new revision`);

    Revisions.insert({
      documentId: product._id,
      documentData: product
    });
  }
});
github ACGN-stock / acgn-stock / server / methods / order / createSellOrder.js View on Github external
throw new Meteor.Error(403, '擁有的股票數量不足,訂單無法成立!');
  }
  const companyData = dbCompanies.findOne(companyId, {
    fields: {
      _id: 1,
      companyName: 1,
      listPrice: 1,
      lastPrice: 1,
      isSeal: 1
    }
  });
  if (! companyData) {
    throw new Meteor.Error(404, '不存在的公司股票,訂單無法成立!');
  }
  if (companyData.isSeal) {
    throw new Meteor.Error(403, `「${companyData.companyName}」公司已被金融管理委員會查封關停了!`);
  }
  if (orderData.unitPrice < Math.max(Math.floor(companyData.listPrice * 0.85), 1)) {
    throw new Meteor.Error(403, '每股單價不可偏離該股票參考價格的百分之十五!');
  }
  if (companyData.listPrice < dbVariables.get('lowPriceThreshold')) {
    if (orderData.unitPrice > Math.ceil(companyData.listPrice * 1.3)) {
      throw new Meteor.Error(403, '每股單價不可高於該股票參考價格的百分之三十!');
    }
  }
  else if (orderData.unitPrice > Math.max(Math.ceil(companyData.listPrice * 1.15), 1)) {
    throw new Meteor.Error(403, '每股單價不可偏離該股票參考價格的百分之十五!');
  }
  resourceManager.throwErrorIsResourceIsLock(['season', 'allCompanyOrders', `companyOrder${companyId}`, `user${userId}`]);
  // 先鎖定資源,再重新讀取一次資料進行運算
  resourceManager.request('createSellOrder', [`companyOrder${companyId}`, `user${userId}`], (release) => {
    const directorData = dbDirectors.findOne({ companyId, userId }, {
github nrkno / tv-automation-server-core / meteor / lib / collections / lib.ts View on Github external
collection[key] = (...args) => {
			try {
				return originalFcn.call(collection, ...args)
			} catch (e) {
				throw new Meteor.Error((e && e.error) || 500, (e && e.reason || e.toString()) || e || 'Unknown MongoDB Error')
			}
		}
	}
github nrkno / tv-automation-server-core / meteor / server / migration / databaseMigration.ts View on Github external
function getMigrationShowStyleContext (chunk: MigrationChunk): IMigrationContextShowStyle {
	if (chunk.sourceType !== MigrationStepType.SHOWSTYLE) throw new Meteor.Error(500, `wrong chunk.sourceType "${chunk.sourceType}", expected SHOWSTYLE`)
	if (!chunk.sourceId) throw new Meteor.Error(500, `chunk.sourceId missing`)

	let showStyleBase = ShowStyleBases.findOne(chunk.sourceId)
	if (!showStyleBase) throw new Meteor.Error(404, `ShowStyleBase "${chunk.sourceId}" not found`)

	return new MigrationContextShowStyle(showStyleBase)
}
github Khan / hivemind / imports / api / entries / methods.js View on Github external
"entry.startDiscussionThread"({entryID}) {
      if (!this.userId) { throw new Meteor.Error('not-authorized'); }

      const entry = Entries.findOne(entryID);
      if (entry.mailingListID) {
        throw new Meteor.Error("Entries.methods.startDiscussionThread.alreadyStarted", "Discussion thread has already been started.");
      } else {
        if (Meteor.isServer) {
          Notifications.sendNewEntryEmail(entryID);
        }
        Entries.update(entryID, {$set: {
          mailingListID: entryID,
          updatedAt: new Date(),
        }});
      }
    },
github RocketChat / Rocket.Chat / app / user-status / server / methods / setUserStatus.js View on Github external
setUserStatus(statusType, statusText) {
		const userId = Meteor.userId();
		if (!userId) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setUserStatus' });
		}

		if (statusType) {
			Meteor.call('UserPresence:setDefaultStatus', statusType);
		}

		if (statusText || statusText === '') {
			check(statusText, String);

			if (!settings.get('Accounts_AllowUserStatusMessageChange')) {
				throw new Meteor.Error('error-not-allowed', 'Not allowed', {
					method: 'setUserStatus',
				});
			}

			setStatusText(userId, statusText);
		}
	},
});
github openpowerquality / opq / view / app / imports / api / base / BaseCollection.js View on Github external
_assertRole(userId, roles) {
    if (!userId) {
      throw new Meteor.Error('unauthorized', 'You must be logged in.');
    } else
      if (!Roles.userIsInRole(userId, roles)) {
        throw new Meteor.Error('unauthorized', `You must be one of the following roles: ${roles}`);
      }
    return true;
  }