How to use the jovo-core.JovoError function in jovo-core

To help you get started, we’ve selected a few jovo-core 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 jovotech / jovo-framework / jovo-platforms / jovo-platform-googleassistant / src / modules / Transaction.ts View on Github external
try {
      const googleapis = require('googleapis').google;

      return googleapis.auth
        .getClient({
          keyFile: this.googleAssistant.config.transactions!.keyFile,
          scopes: ['https://www.googleapis.com/auth/actions.purchases.digital'],
        })
        .then((client: any) => client.authorize()) // tslint:disable-line
        .then((authorization: any) => authorization.access_token as string); // tslint:disable-line
    } catch (e) {
      console.log(e);
      console.log(e.stack);
      if (e.message === "Cannot find module 'googleapis'") {
        return Promise.reject(
          new JovoError(
            e.message,
            ErrorCode.ERR,
            'jovo-platform-googleassistant',
            undefined,
            'Please run `npm install googleapis`',
          ),
        );
      }
      return Promise.reject(new Error('Could not retrieve Google API access token'));
    }
  }
}
github jovotech / jovo-framework / jovo-integrations / jovo-cms-googlesheets / src / DefaultSheet.ts View on Github external
parse(handleRequest: HandleRequest, values: any[]) {
    // tslint:disable-line
    if (!this.config.entity) {
      throw new JovoError(
        'entity has to be set.',
        ErrorCode.ERR_PLUGIN,
        'jovo-cms-googlesheets',
        `The sheet's name has to be defined in your config.js file.`,
        undefined,
        'https://www.jovo.tech/docs/cms/google-sheets#configuration',
      );
    }
    handleRequest.app.$cms[this.config.entity] = values;
  }
github jovotech / jovo-framework / jovo-integrations / jovo-db-mongodb / src / MongoDb.ts View on Github external
async load(primaryKey: string): Promise {
    // tslint:disable-line
    try {
      await this.initClient();
      const collection = this.client!.db(this.config.databaseName!).collection(
        this.config.collectionName!,
      );
      const doc = await collection.findOne({ userId: primaryKey });
      return doc;
    } catch (e) {
      throw new JovoError(
        e.message,
        ErrorCode.ERR_PLUGIN,
        'jovo-db-mongodb',
        undefined,
        'Make sure the configuration you provided is valid.',
        'https://www.jovo.tech/docs/databases/mongodb',
      );
    }
  }
github jovotech / jovo-framework / jovo-integrations / jovo-db-dynamodb / src / DynamoDb.ts View on Github external
ErrorCode.ERR_PLUGIN,
            'jovo-db-dynamodb',
            undefined,
            'Please run `npm install aws-xray-sdk-core`',
          );
        } else {
          throw e;
        }
      }
    }

    this.dynamoClient = new this.aws.DynamoDB(this.config.dynamoDbConfig);

    if (this.config.dax) {
      if (this.config.awsXray) {
        throw new JovoError(
          `DynamoDB Accelerator doesn't work with AWS X-Ray`,
          ErrorCode.ERR_PLUGIN,
          'jovo-db-dynamodb',
        );
      }

      try {
        const AmazonDaxClient = require('amazon-dax-client'); // tslint:disable-line
        const dax = new AmazonDaxClient(this.config.dax);
        this.docClient = new this.aws.DynamoDB.DocumentClient({ service: dax });
      } catch (e) {
        if (e.message.includes(`Cannot find module 'amazon-dax-client'`)) {
          throw new JovoError(
            e.message,
            ErrorCode.ERR_PLUGIN,
            'jovo-db-dynamodb',
github jovotech / jovo-framework / jovo-integrations / jovo-platform-googleassistant / src / modules / DigitalGoods.ts View on Github external
* googleapis has to be manually installed
       */
      try {
          const googleapis = require('googleapis').google;

          return googleapis.google.auth.getClient({
              keyFile: this.googleAssistant.config.transactions!.keyFile,
              scopes: [ 'https://www.googleapis.com/auth/actions.purchases.digital' ]
          })
              .then((client: any) => client.authorize()) // tslint:disable-line
              .then((authorization: any) => authorization.access_token as string); // tslint:disable-line

      } catch (e) {

          if (e.message === 'Cannot find module \'googleapis\'') {
              Promise.reject(new JovoError(
                  e.message,
                  ErrorCode.ERR,
                  'jovo-platform-googleassistant',
                  undefined,
                  'Please run `npm install googleapis`'
              ));
          }
      }
      return Promise.reject(new Error('Could not retrieve Google API access token'));
  }
}
github jovotech / jovo-framework / dist / src / GoogleAnalyticsSender.js View on Github external
install(app) {
        if (!this.config.trackingId) {
            throw new jovo_core_1.JovoError("Google Analytics tracking id was not found.", jovo_core_1.ErrorCode.ERR_PLUGIN, 'jovo-analytics-googleanalytics', "trackingId needs to be added to config.js. See https://www.jovo.tech/docs/analytics/dashbot for details.", "You can find your tracking id in GoogleAnalytics by clicking: Admin -> Property Settings -> Tracking Id");
        }
        else {
            console.log("tracking id is: " + this.config.trackingId);
            app.middleware('platform.nlu').use(this.setJovoObjectAccess.bind(this));
            app.middleware('after.response').use(this.sendDataToGA.bind(this)); //use(this.track);
            app.middleware('fail').use(this.sendErrorToGA.bind(this));
            console.log("added GA events");
        }
    }
    uninstall(parent) {
github jovotech / jovo-framework / src / GoogleAnalyticsSender.ts View on Github external
install(app: BaseApp): void {
        if (!this.config.trackingId) {
            throw new JovoError("Google Analytics tracking id was not found.",
                ErrorCode.ERR_PLUGIN,
                'jovo-analytics-googleanalytics',
                "trackingId needs to be added to config.js. See https://www.jovo.tech/docs/analytics/dashbot for details.",
                "You can find your tracking id in GoogleAnalytics by clicking: Admin -> Property Settings -> Tracking Id"
            )
        }
        else {
            console.log("tracking id is: " + this.config.trackingId);
            app.middleware('platform.nlu')!.use(this.setJovoObjectAccess.bind(this));
            app.middleware('after.response')!.use(this.sendDataToGA.bind(this));//use(this.track);
            app.middleware('fail')!.use(this.sendErrorToGA.bind(this));
            console.log("added GA events");
        }
    }
    uninstall(parent?: any): void {
github jovotech / jovo-framework / jovo-platforms / jovo-platform-googleassistant / src / modules / Notification.ts View on Github external
sendNotification(notification: NotificationObject, accessToken: string) {
    if (!notification) {
      throw new JovoError(
        "Couldn't send notification. notification has to be set",
        ErrorCode.ERR,
        'jovo-platform-googleassistant',
        undefined,
        undefined,
        'https://www.jovo.tech/docs/google-assistant/notifications#notification-object',
      );
    }

    if (!accessToken) {
      throw new JovoError(
        "Couldn't send notification. accessToken has to be set.",
        ErrorCode.ERR,
        'jovo-platform-googleassistant',
        undefined,
        'Get an access token using `this.$googleAction.$notification.getAccessToken(clientEmail, privateKey)`',
github jovotech / jovo-framework / jovo-platforms / jovo-platform-googleassistant / src / modules / Notification.ts View on Github external
async sendAuthRequest(clientEmail: string, privateKey: string) {
    if (!clientEmail || !privateKey) {
      throw new JovoError(
        "Couldn't authenticate. clientEmail and privateKey have to be set",
        ErrorCode.ERR,
        'jovo-platform-googleassistant',
        "To authorize yourself, you have to provide your service account's clientEmail and privateKey",
        undefined,
        'https://www.jovo.tech/docs/google-assistant/notifications#configuration',
      );
    }

    const jwtClient = new this.google.auth.JWT(
      clientEmail,
      undefined,
      privateKey,
      ['https://www.googleapis.com/auth/actions.fulfillment.conversation'],
      undefined,
    );
github jovotech / jovo-framework / jovo-integrations / jovo-analytics-googleanalytics / src / GoogleAnalytics.ts View on Github external
install(app: BaseApp) {
    if (!this.config.trackingId) {
      throw new JovoError(
        'trackingId has to be set.',
        ErrorCode.ERR_PLUGIN,
        'jovo-analytics-googleanalytics',
        '',
        'You can find your tracking id in Google Analytics by clicking: Admin -> Property Settings -> Tracking Id',
        'https://www.jovo.tech/docs/analytics/googleanalytics',
      );
    }

    app.middleware('after.platform.init')!.use(this.setGoogleAnalyticsObject.bind(this));
    app.middleware('after.response')!.use(this.track.bind(this));
    app.middleware('fail')!.use(this.sendError.bind(this));
  }

jovo-core

jovo-core

Apache-2.0
Latest version published 3 years ago

Package Health Score

34 / 100
Full package analysis

Popular jovo-core functions