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

To help you get started, we’ve selected a few ask-sdk 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-v1adapter / lib / adapter.ts View on Github external
function ValidateRequest() : void {
    let requestAppId = '';
    if (this._event.context) {
        requestAppId = this._event.context.System.application.applicationId;
    } else if (this._event.session) {
        requestAppId = this._event.session.application.applicationId;
    }

    if (!this.appId) {
        console.log('Warning: Application ID is not set');
    }
    try {
        if (this.appId && (requestAppId !== this.appId)) {
            console.log(`The applicationIds don\'t match: ${requestAppId} and ${this.appId}`);
            const error = createAskSdkError('In validating request', 'Invalid ApplicationId: ' + this.appId);
            if (typeof this.callback === 'undefined') {
                this._context.fail(error);
            } else {
                this._callback(error);
            }
        }

        if (this.dynamoDBTableName && (!this._event.session.sessionId || this._event.session.new)) {
            if (!dynamoDbPersistenceAdapter) {
                dynamoDbPersistenceAdapter = new DynamoDbPersistenceAdapter({
                    createTable : true,
                    dynamoDBClient : this.dynamoDBClient,
                    partitionKeyName : 'userId',
                    attributesName : 'mapAttr',
                    tableName : this.dynamoDBTableName,
                });
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-v1adapter / lib / handler.ts View on Github external
return new Promise((resolve, reject) => {
            this.adapter.promiseResolve = resolve;
            try {
                if (this.adapter.listenerCount(this.targetHandlerName + this.adapter.state) >= 1) {
                    this.adapter.emit(this.targetHandlerName + this.adapter.state);
                } else if (this.adapter.listenerCount('Unhandled' + this.adapter.state) >= 1) {
                    this.adapter.emit('Unhandled' + this.adapter.state);
                } else {
                    reject(createAskSdkError(
                        this.constructor.name,
                        `In state: ${this.adapter.state}. No handler function was defined for event ${this.targetHandlerName} and no 'Unhandled' function was defined.`));
                }
            } catch (e) {
                reject(e);
            }
        });
    }
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-v1adapter / lib / adapter.ts View on Github external
function EmitWithState() : void {
    if (arguments.length === 0) {
        throw createAskSdkError(this.constructor.name, 'EmitWithState called without arguments');
    }
    arguments[0] = arguments[0] + this.state;

    if (this.listenerCount(arguments[0]) < 1) {
        arguments[0] = 'Unhandled' + this.state;
    }

    if (this.listenerCount(arguments[0]) < 1) {
        throw createAskSdkError(this.constructor.name, `No 'Unhandled' function defined for event: ${arguments[0]}`);
    }

    this.emit.apply(this, arguments);
}
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-v1adapter / lib / adapter.ts View on Github external
public registerHandlers(...v1Handlers : V1Handler[]) : void {
        for ( const handler of v1Handlers) {
            if (!IsObject(handler)) {
                throw createAskSdkError(this.constructor.name, `Argument #${handler.constructor.name} was not an Object`);
            }
            const eventNames = Object.keys(handler);
            for (const eventName of eventNames) {
                if (typeof(handler[eventName]) !== 'function') {
                    throw createAskSdkError(this.constructor.name, `Event handler for '${eventName}' was not a function`);
                }

                let targetEventName = eventName;

                if (handler[StateString as any]) {
                    targetEventName += handler[StateString as any];
                }

                const handlerContext = {
                    on: this.on.bind(this),
                    emit: this.emit.bind(this),
                    emitWithState: EmitWithState.bind(this),
                    handler: this,
                    i18n: this.i18n,
                    locale: this.locale,
                    t : (...argArray : string[]) : string => {
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-v1adapter / lib / adapter.ts View on Github external
},                          (err) => {
                if (err) {
                    throw createAskSdkError(this.constructor.name, 'Error initializing i19next: ' + err);
                }
                ValidateRequest.call(this);
            });
        } else {
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-v1adapter / lib / adapter.ts View on Github external
public registerHandlers(...v1Handlers : V1Handler[]) : void {
        for ( const handler of v1Handlers) {
            if (!IsObject(handler)) {
                throw createAskSdkError(this.constructor.name, `Argument #${handler.constructor.name} was not an Object`);
            }
            const eventNames = Object.keys(handler);
            for (const eventName of eventNames) {
                if (typeof(handler[eventName]) !== 'function') {
                    throw createAskSdkError(this.constructor.name, `Event handler for '${eventName}' was not a function`);
                }

                let targetEventName = eventName;

                if (handler[StateString as any]) {
                    targetEventName += handler[StateString as any];
                }

                const handlerContext = {
                    on: this.on.bind(this),
                    emit: this.emit.bind(this),
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-v1adapter / lib / adapter.ts View on Github external
function EmitWithState() : void {
    if (arguments.length === 0) {
        throw createAskSdkError(this.constructor.name, 'EmitWithState called without arguments');
    }
    arguments[0] = arguments[0] + this.state;

    if (this.listenerCount(arguments[0]) < 1) {
        arguments[0] = 'Unhandled' + this.state;
    }

    if (this.listenerCount(arguments[0]) < 1) {
        throw createAskSdkError(this.constructor.name, `No 'Unhandled' function defined for event: ${arguments[0]}`);
    }

    this.emit.apply(this, arguments);
}
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-v1adapter / lib / adapter.ts View on Github external
.catch((error) => {
                    const err = createAskSdkError(this.constructor.name, 'Error fetching user state: ' + error);
                    if (typeof this._callback === 'undefined') {
                        return this._context.fail(err);
                    } else {
                        return this._callback(err);
                    }
                });
        } else {

ask-sdk

Standard distribution package for Alexa Skills Kit SDK

Apache-2.0
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis