How to use the italia-ts-commons/lib/reporters.readableReport function in italia-ts-commons

To help you get started, we’ve selected a few italia-ts-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
// as the notification object is retrieved from database (?)
    return left(
      TransientError(
        `Notification not found|notification=${notificationId}|message=${
          message.id
        }`
      )
    );
  }

  const errorOrEmailNotification = EmailNotification.decode(
    maybeEmailNotification.value
  );

  if (isLeft(errorOrEmailNotification)) {
    const error = readableReport(errorOrEmailNotification.value);
    return left(
      PermanentError(
        `Wrong format for email notification|notification=${notificationId}|message=${
          message.id
        }|${error}`
      )
    );
  }

  const emailNotification = errorOrEmailNotification.value.channels.EMAIL;

  const documentHtml = await generateDocumentHtml(
    content.subject,
    content.markdown,
    senderMetadata
  );
github teamdigitale / io-functions / lib / controllers / messages.ts View on Github external
serviceVersion: userAttributes.service.version
      })
    );

    if (isLeft(createdMessageEventOrError)) {
      winston.error(
        `CreateMessageHandler|Unable to decode CreatedMessageEvent|${
          userService.serviceId
        }|${retrievedMessage.id}|${readableReport(
          createdMessageEventOrError.value
        ).replace(/\n/g, " / ")}`
      );

      return ResponseErrorValidation(
        "Unable to decode CreatedMessageEvent",
        readableReport(createdMessageEventOrError.value)
      );
    }

    // queue the message to the created messages queue by setting
    // the message to the output binding of this function
    // tslint:disable-next-line:no-object-mutation
    context.bindings.createdMessage = createdMessageEventOrError.value;

    //
    // generate appinsights event
    //

    // track the event that a message has been created
    appInsightsClient.trackEvent({
      measurements: {
        duration: diffInMilliseconds(startRequestTime)
github teamdigitale / io-functions / lib / emailnotifications_queue_handler.ts View on Github external
winston.debug(
    `EmailNotificationsHandlerIndex|Dequeued email notification|${JSON.stringify(
      context.bindings
    )}`
  );

  // since this function gets triggered by a queued message that gets
  // deserialized from a json object, we must first check that what we
  // got is what we expect.
  const errorOrNotificationEvent = NotificationEvent.decode(
    context.bindings.notificationEvent
  );
  if (isLeft(errorOrNotificationEvent)) {
    winston.error(
      `EmailNotificationsHandler|Fatal! No valid message found in bindings.|${readableReport(
        errorOrNotificationEvent.value
      )}`
    );
    return stopProcessing;
  }
  const emailNotificationEvent = errorOrNotificationEvent.value;

  const notificationStatusUpdater = getNotificationStatusUpdater(
    notificationStatusModel,
    NotificationChannelEnum.EMAIL,
    emailNotificationEvent.message.id,
    emailNotificationEvent.notificationId
  );

  winston.debug(`useSendgridTransport:${useSendgridTransport}`);
github teamdigitale / io-functions / lib / webhook_queue_handler.ts View on Github external
// 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=${
          message.id
        }|${error}`
      )
    );
  }

  const webhookNotification = errorOrWebhookNotification.value.channels.WEBHOOK;

  const startWebhookCallTime = process.hrtime();

  const sendResult = await sendToWebhook(
    webhookNotification.url,
    message,
github teamdigitale / io-functions / lib / webhook_queue_handler.ts View on Github external
winston.debug(
    `WebhookNotificationsHandlerIndex|Dequeued webhook notification|${JSON.stringify(
      context.bindings
    )}`
  );

  // since this function gets triggered by a queued message that gets
  // deserialized from a json object, we must first check that what we
  // got is what we expect.
  const errorOrNotificationEvent = NotificationEvent.decode(
    context.bindings.notificationEvent
  );
  if (isLeft(errorOrNotificationEvent)) {
    winston.error(
      `WebhookNotificationsHandler|Fatal! No valid message found in bindings.|${readableReport(
        errorOrNotificationEvent.value
      )}`
    );
    return;
  }
  const webhookNotificationEvent = errorOrNotificationEvent.value;

  const notificationStatusUpdater = getNotificationStatusUpdater(
    notificationStatusModel,
    NotificationChannelEnum.WEBHOOK,
    webhookNotificationEvent.message.id,
    webhookNotificationEvent.notificationId
  );

  const serviceId = webhookNotificationEvent.message.senderServiceId;
github teamdigitale / io-functions / lib / controllers / messages.ts View on Github external
message: newMessageWithoutContent,
        senderMetadata: {
          departmentName: userAttributes.service.departmentName,
          organizationFiscalCode: userAttributes.service.organizationFiscalCode,
          organizationName: userAttributes.service.organizationName,
          serviceName: userAttributes.service.serviceName
        },
        serviceVersion: userAttributes.service.version
      })
    );

    if (isLeft(createdMessageEventOrError)) {
      winston.error(
        `CreateMessageHandler|Unable to decode CreatedMessageEvent|${
          userService.serviceId
        }|${retrievedMessage.id}|${readableReport(
          createdMessageEventOrError.value
        ).replace(/\n/g, " / ")}`
      );

      return ResponseErrorValidation(
        "Unable to decode CreatedMessageEvent",
        readableReport(createdMessageEventOrError.value)
      );
    }

    // queue the message to the created messages queue by setting
    // the message to the output binding of this function
    // tslint:disable-next-line:no-object-mutation
    context.bindings.createdMessage = createdMessageEventOrError.value;

    //
github teamdigitale / io-functions / lib / utils / azure_storage.ts View on Github external
        type.decode(parsedJson).mapLeft(errs => new Error(readableReport(errs)))
      )
github teamdigitale / io-functions / lib / profile_events_queue_handler.ts View on Github external
}).getOrElseL(errs => {
      throw new Error(
        "Invalid MessageContent for welcome message: " + readableReport(errs)
      );
    }),
  (_: ExtendedProfile) =>
github teamdigitale / io-functions / lib / models / message.ts View on Github external
return RetrievedMessage.decode(result).getOrElseL(errs => {
    throw new Error(
      "Retrieved result wasn't a RetrievedMessage: " + readableReport(errs)
    );
  });
}