Skip to content

Commit

Permalink
Catch the Lex error since Lex only supports 15s speech (#130)
Browse files Browse the repository at this point in the history
* catch error and rethrow the error from Lex PostContent api when the recording speech is more than 15s
  • Loading branch information
eherozhao authored Jun 3, 2022
1 parent 208f779 commit 0119829
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/amazon-sumerian-hosts-core/src/core/awspack/LexFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,16 @@ class LexFeature extends Messenger {
}
return resolve(data);
});
}).then(data => {
this.emit(this.constructor.EVENTS.lexResponseReady, data);

return data;
});
})
.then(data => {
this.emit(this.constructor.EVENTS.lexResponseReady, data);
return data;
})
.catch(error => {
const errorMessage = `Error happened during voice recording: ${error}. Please check whether your speech is more than 15s.`;
console.error(errorMessage);
throw new Error(errorMessage);
});
}

_validateConfig(config) {
Expand Down Expand Up @@ -248,7 +253,6 @@ class LexFeature extends Messenger {
}

this.emit(this.constructor.EVENTS.recordEnd);

return this._processWithAudio(result, this._audioContext.sampleRate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ describeEnvironment('LexFeature', () => {
{message: 'TestResponse'}
);
});

it('The error re-thrown from _process should be equal to the customize one.', async () => {
mockLexRuntime.postContent.and.callFake(function(param, callback) {
callback(new Error('mock error'), {message: 'TestResponse'});
});
lexFeature = new LexFeature(mockLexRuntime, {
botName: 'Bot',
botAlias: 'Alias',
});

await expectAsync(
lexFeature._process('TestType', 'TestInput', {})
).toBeRejectedWithError(
'Error happened during voice recording: Error: mock error. Please check whether your speech is more than 15s.'
);
});
});

describe('enableMicInput', () => {
Expand Down

0 comments on commit 0119829

Please sign in to comment.