How to use the io-functions-commons/dist/src/utils/errors.RecipientError function in io-functions-commons

To help you get started, we’ve selected a few io-functions-commons 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 teamdigitale / io-functions / lib / created_message_queue_handler.ts View on Github external
if (!isInboxEnabled) {
    // the recipient's inbox is disabled
    return left(
      RecipientError("Recipient inbox is disabled.")
    );
  }

  // whether the user has blocked inbox storage for messages from this sender
  const isMessageStorageBlockedForService = blockedInboxOrChannels.has(
    BlockedInboxOrChannelEnum.INBOX
  );

  if (isMessageStorageBlockedForService) {
    // the recipient's inbox is disabled
    return left(
      RecipientError("Sender is blocked by recipient.")
    );
  }

  // Save the content of the message to the blob storage.
  // In case of a retry this operation will overwrite the message content with itself
  // (this is fine as we don't know if the operation succeeded at first)
  const errorOrAttachment = await lMessageModel.attachStoredContent(
    lBlobService,
    newMessageWithoutContent.id,
    newMessageWithoutContent.fiscalCode,
    createdMessageEvent.content
  );
  if (isLeft(errorOrAttachment)) {
    return left(
      TransientError("Cannot store message content")
    );
github teamdigitale / io-functions / lib / created_message_queue_handler.ts View on Github external
"handleMessage|Blocked Channels(%s): %s",
    newMessageWithoutContent.fiscalCode,
    JSON.stringify(blockedInboxOrChannels)
  );

  //
  //  Inbox storage
  //

  // a profile exists and the global inbox flag is enabled
  const isInboxEnabled = profile.isInboxEnabled === true;

  if (!isInboxEnabled) {
    // the recipient's inbox is disabled
    return left(
      RecipientError("Recipient inbox is disabled.")
    );
  }

  // whether the user has blocked inbox storage for messages from this sender
  const isMessageStorageBlockedForService = blockedInboxOrChannels.has(
    BlockedInboxOrChannelEnum.INBOX
  );

  if (isMessageStorageBlockedForService) {
    // the recipient's inbox is disabled
    return left(
      RecipientError("Sender is blocked by recipient.")
    );
  }

  // Save the content of the message to the blob storage.
github teamdigitale / io-functions / lib / created_message_queue_handler.ts View on Github external
if (isLeft(errorOrMaybeProfile)) {
    // The query has failed.
    // It's *critical* to trigger a retry here
    // otherwise no message content will be saved
    return left(
      TransientError("Cannot get user's profile")
    );
  }

  const maybeProfile = errorOrMaybeProfile.value;

  if (isNone(maybeProfile)) {
    // the recipient doesn't have any profile yet
    return left(
      RecipientError("Recipient profile does not exist.")
    );
  }

  const profile = maybeProfile.value;

  // channels ther user has blocked for this sender service
  const blockedInboxOrChannels = fromNullable(profile.blockedInboxOrChannels)
    .chain((bc: IProfileBlockedInboxOrChannels) =>
      fromNullable(bc[newMessageWithoutContent.senderServiceId])
    )
    .getOrElse(new Set());

  winston.debug(
    "handleMessage|Blocked Channels(%s): %s",
    newMessageWithoutContent.fiscalCode,
    JSON.stringify(blockedInboxOrChannels)

io-functions-commons

Common code for Azure functions

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Similar packages