How to use the io-functions-commons/dist/src/utils/errors.TransientError 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 / emailnotifications_queue_handler.ts View on Github external
addressSource: emailNotification.addressSource,
      transport: lMailerTransporter.transporter.name
    }
  };

  if (isLeft(sendResult)) {
    const error = sendResult.value;
    // track the event of failed delivery
    lAppInsightsClient.trackDependency({
      ...eventContent,
      data: error.message,
      resultCode: error.name,
      success: false
    });
    return left(
      TransientError(
        `Error while sending email|notification=${notificationId}|message=${
          message.id
        }|error=${error.message}`
      )
    );
  }

  // track the event of successful delivery
  lAppInsightsClient.trackDependency({
    ...eventContent,
    data: "OK",
    resultCode: 200,
    success: true
  });

  // TODO: handling bounces and delivery updates
github teamdigitale / io-functions / lib / utils / azure_queues.ts View on Github external
callbackError =>
            handleQueueProcessingFailure(
              queueService,
              queueMessageBindings,
              queueName,
              onTransientError,
              onPermanentError,
              TransientError(callbackError.message)
            ),
          // exits (stop processing) in case no error
github teamdigitale / io-functions / lib / webhook_queue_handler.ts View on Github external
`Message expired|notification=${notificationId}|message=${message.id}`
      )
    );
  }

  // fetch the notification
  const errorOrMaybeNotification = await lNotificationModel.find(
    notificationId,
    message.id
  );

  if (isLeft(errorOrMaybeNotification)) {
    const error = errorOrMaybeNotification.value;
    // we got an error while fetching the notification
    return left(
      TransientError(
        `Error while fetching the notification|notification=${notificationId}|message=${
          message.id
        }|error=${error.code}`
      )
    );
  }

  const maybeWebhookNotification = errorOrMaybeNotification.value;

  if (isNone(maybeWebhookNotification)) {
    // it may happen that the object is not yet visible to this function due to latency
    // as the notification object is retrieved from database (?)
    return left(
      TransientError(
        `Notification not found|notification=${notificationId}|message=${
          message.id
github teamdigitale / io-functions / lib / webhook_queue_handler.ts View on Github external
async error => {
          if (isExpiredError(error)) {
            // message is expired. try to save the notification status into the database
            const errorOrUpdateNotificationStatus = await notificationStatusUpdater(
              NotificationChannelStatusValueEnum.EXPIRED
            );
            if (isLeft(errorOrUpdateNotificationStatus)) {
              // retry the whole handler in case we cannot save
              // the notification status into the database
              throw TransientError(
                errorOrUpdateNotificationStatus.value.message
              );
            }
            // if the message is expired we're done, stop here
            return;
          }
          // for every other kind of error
          // delegate to the catch handler
          throw error;
        },
        async _ => {
github teamdigitale / io-functions / lib / created_message_queue_handler.ts View on Github external
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")
    );
  }

  // Now that the message content has been stored, we can make the message
  // visible to getMessages by changing the pending flag to false
  const updatedMessageOrError = await lMessageModel.createOrUpdate(
    {
      ...newMessageWithoutContent,
      isPending: false
    },
    createdMessageEvent.message.fiscalCode
  );
  if (isLeft(updatedMessageOrError)) {
    return left(
      TransientError("Cannot update message pending status")
    );
github teamdigitale / io-functions / lib / webhook_queue_handler.ts View on Github external
return left(
      TransientError(
        `Error while fetching the notification|notification=${notificationId}|message=${
          message.id
        }|error=${error.code}`
      )
    );
  }

  const maybeWebhookNotification = errorOrMaybeNotification.value;

  if (isNone(maybeWebhookNotification)) {
    // it may happen that the object is not yet visible to this function due to latency
    // as the notification object is retrieved from database (?)
    return left(
      TransientError(
        `Notification not found|notification=${notificationId}|message=${
          message.id
        }`
      )
    );
  }

  const errorOrWebhookNotification = WebhookNotification.decode(
    maybeWebhookNotification.value
  );

  if (isLeft(errorOrWebhookNotification)) {
    const error = readableReport(errorOrWebhookNotification.value);
    return left(
      PermanentError(
        `Wrong format for webhook notification|notification=${notificationId}|message=${
github teamdigitale / io-functions / lib / webhook_queue_handler.ts View on Github external
response => {
        if (response.error) {
          return left(
            // in case of server HTTP 5xx errors we trigger a retry
            response.serverError
              ? TransientError(
                  `Transient HTTP error calling API Proxy: ${response.text}`
                )
              : PermanentError(
                  `Permanent HTTP error calling API Proxy: ${response.text}`
                )
          );
        }
        return right(response);
      },
      err => {
github teamdigitale / io-functions / lib / created_message_queue_handler.ts View on Github external
async function createNotification(
  lNotificationModel: NotificationModel,
  senderMetadata: CreatedMessageEventSenderMetadata,
  newMessageWithoutContent: NewMessageWithoutContent,
  newMessageContent: MessageContent,
  newNotification: NewNotification
): Promise> {
  const errorOrNotification = await lNotificationModel.create(
    newNotification,
    newNotification.messageId
  );

  if (isLeft(errorOrNotification)) {
    return left(
      TransientError("Cannot save notification to database")
    );
  }

  const notification = errorOrNotification.value;

  const notificationEvent: NotificationEvent = {
    content: newMessageContent,
    message: newMessageWithoutContent,
    notificationId: notification.id,
    senderMetadata
  };
  return right(notificationEvent);
}

io-functions-commons

Common code for Azure functions

MIT
Latest version published 4 years ago

Package Health Score

46 / 100
Full package analysis

Similar packages