How to use the ask-sdk-core.createAskSdkError function in ask-sdk-core

To help you get started, we’ve selected a few ask-sdk-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 alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-s3-persistence-adapter / lib / attributes / persistence / S3PersistenceAdapter.ts View on Github external
public async saveAttributes(requestEnvelope : RequestEnvelope, attributes : {[key : string] : string}) : Promise {
        const objectId = path.join(this.pathPrefix, this.objectKeyGenerator(requestEnvelope));

        const putParams : S3.PutObjectRequest = {
            Bucket : this.bucketName,
            Key : objectId,
            Body : JSON.stringify(attributes),
        };

        try {
            await this.s3Client.putObject(putParams).promise();
        } catch (err) {
            throw createAskSdkError(
                this.constructor.name,
                `Could not save item (${objectId}) to bucket (${putParams.Bucket}): ${err.message}`,
            );
        }
    }
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-s3-persistence-adapter / lib / attributes / persistence / ObjectKeyGenerators.ts View on Github external
deviceId(requestEnvelope : RequestEnvelope) : string {
        if (!(requestEnvelope
              && requestEnvelope.context
              && requestEnvelope.context.System
              && requestEnvelope.context.System.device
              && requestEnvelope.context.System.device.deviceId)) {
            throw createAskSdkError(
                'PartitionKeyGenerators',
                'Cannot retrieve device id from request envelope!',
            );
        }

        return requestEnvelope.context.System.device.deviceId;
    },
};
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-s3-persistence-adapter / lib / attributes / persistence / ObjectKeyGenerators.ts View on Github external
userId(requestEnvelope : RequestEnvelope) : string {
        if (!(requestEnvelope
              && requestEnvelope.context
              && requestEnvelope.context.System
              && requestEnvelope.context.System.user
              && requestEnvelope.context.System.user.userId)) {
            throw createAskSdkError(
                'PartitionKeyGenerators',
                'Cannot retrieve user id from request envelope!',
            );
        }

        return requestEnvelope.context.System.user.userId;
    },
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-dynamodb-persistence-adapter / lib / attributes / persistence / DynamoDbPersistenceAdapter.ts View on Github external
this.dynamoDBClient.createTable(createTableParams, (createTableErr) => {
                if (createTableErr && createTableErr.code !== 'ResourceInUseException') {
                    throw createAskSdkError(
                        this.constructor.name,
                        `Could not create table (${this.tableName}): ${createTableErr.message}`,
                    );
                }
            });
        }
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-dynamodb-persistence-adapter / lib / attributes / persistence / DynamoDbPersistenceAdapter.ts View on Github external
public async deleteAttributes(requestEnvelope : RequestEnvelope) : Promise {
        const attributesId = this.partitionKeyGenerator(requestEnvelope);

        const deleteParams : DynamoDB.DocumentClient.DeleteItemInput = {
            Key : {
                [this.partitionKeyName] : attributesId,
            },
            TableName : this.tableName,
        };

        try {
            await this.dynamoDBDocumentClient.delete(deleteParams).promise();
        } catch (err) {
            throw createAskSdkError(
                this.constructor.name,
                `Could not delete item (${attributesId}) from table (${deleteParams.TableName}): ${err.message}`,
            );
        }
    }
}
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-dynamodb-persistence-adapter / lib / attributes / persistence / PartitionKeyGenerators.ts View on Github external
deviceId(requestEnvelope : RequestEnvelope) : string {
        if (!(requestEnvelope
              && requestEnvelope.context
              && requestEnvelope.context.System
              && requestEnvelope.context.System.device
              && requestEnvelope.context.System.device.deviceId)) {
            throw createAskSdkError(
                'PartitionKeyGenerators',
                'Cannot retrieve device id from request envelope!',
            );
        }

        return requestEnvelope.context.System.device.deviceId;
    },
};
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-s3-persistence-adapter / lib / attributes / persistence / S3PersistenceAdapter.ts View on Github external
const getParams : S3.GetObjectRequest = {
            Bucket : this.bucketName,
            Key : objectId,
        };

        let data : S3.GetObjectOutput;

        try {
            data = await this.s3Client.getObject(getParams).promise();
        } catch (err) {
            if (err.code === 'NoSuchKey') {
                return {};
            }

            throw createAskSdkError(
                this.constructor.name,
                `Could not read item (${objectId}) from bucket (${getParams.Bucket}): ${err.message}`,
            );
        }

        const bodyString = data.Body ? data.Body.toString() : '';

        let bodyObj;

        try {
            bodyObj = bodyString ? JSON.parse(bodyString) : {};
        } catch (err) {
            throw new SyntaxError(`Failed trying to parse the data body: ${data.Body.toString()}`);
        }

        return bodyObj;
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-s3-persistence-adapter / lib / attributes / persistence / S3PersistenceAdapter.ts View on Github external
public async deleteAttributes(requestEnvelope : RequestEnvelope) : Promise {
        const objectId = path.join(this.pathPrefix, this.objectKeyGenerator(requestEnvelope));

        const deleteParams : S3.DeleteObjectRequest = {
            Bucket : this.bucketName,
            Key : objectId,
        };

        try {
            await this.s3Client.deleteObject(deleteParams).promise();
        } catch (err) {
            throw createAskSdkError(
                this.constructor.name,
                `Could not delete item (${objectId}) from bucket (${deleteParams.Bucket}): ${err.message}`,
            );
        }
    }
}
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-dynamodb-persistence-adapter / lib / attributes / persistence / DynamoDbPersistenceAdapter.ts View on Github external
public async saveAttributes(requestEnvelope : RequestEnvelope, attributes : {[key : string] : any}) : Promise {
        const attributesId = this.partitionKeyGenerator(requestEnvelope);

        const putParams : DynamoDB.DocumentClient.PutItemInput = {
            Item: {
                [this.partitionKeyName] : attributesId,
                [this.attributesName] : attributes,
            },
            TableName : this.tableName,
        };

        try {
            await this.dynamoDBDocumentClient.put(putParams).promise();
        } catch (err) {
            throw createAskSdkError(
                this.constructor.name,
                `Could not save item (${attributesId}) to table (${putParams.TableName}): ${err.message}`,
            );
        }
    }
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-dynamodb-persistence-adapter / lib / attributes / persistence / DynamoDbPersistenceAdapter.ts View on Github external
public async getAttributes(requestEnvelope : RequestEnvelope) : Promise<{[key : string] : any}> {
        const attributesId = this.partitionKeyGenerator(requestEnvelope);

        const getParams : DynamoDB.DocumentClient.GetItemInput = {
            Key : {
                [this.partitionKeyName] : attributesId,
            },
            TableName : this.tableName,
            ConsistentRead : true,
        };

        let data : DynamoDB.DocumentClient.GetItemOutput;
        try {
            data = await this.dynamoDBDocumentClient.get(getParams).promise();
        } catch (err) {
            throw createAskSdkError(
                this.constructor.name,
                `Could not read item (${attributesId}) from table (${getParams.TableName}): ${err.message}`,
            );
        }

        if (!Object.keys(data).length) {
            return {};
        } else {
            return data.Item[this.attributesName];
        }
    }