Skip to content

Commit 4211ecb

Browse files
speech: throw if required config is missing (#2003)
1 parent 116103a commit 4211ecb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/google-cloud-speech/src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ Speech.formatResults_ = function(resultSets, verboseMode) {
483483
Speech.prototype.createRecognizeStream = function(config) {
484484
var self = this;
485485

486+
if (!config) {
487+
throw new Error('A recognize request requires a configuration object.');
488+
}
489+
486490
var verboseMode = config.verbose === true;
487491
delete config.verbose;
488492

@@ -657,6 +661,10 @@ Speech.prototype.operation = function(name) {
657661
Speech.prototype.recognize = function(file, config, callback) {
658662
var self = this;
659663

664+
if (!is.object(config)) {
665+
throw new Error('A recognize request requires a configuration object.');
666+
}
667+
660668
config = extend({}, config);
661669

662670
if (!config.encoding) {

packages/google-cloud-speech/test/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ describe('Speech', function() {
472472
};
473473
});
474474

475+
it('should throw if an object is not provided', function() {
476+
assert.throws(function() {
477+
speech.createRecognizeStream();
478+
}, /A recognize request requires a configuration object\./);
479+
});
480+
475481
it('should make the correct request once writing started', function(done) {
476482
speech.api.Speech = {
477483
streamingRecognize: function() {
@@ -698,6 +704,12 @@ describe('Speech', function() {
698704
};
699705
});
700706

707+
it('should throw if an object is not provided', function() {
708+
assert.throws(function() {
709+
speech.recognize(FILE, assert.ifError);
710+
}, /A recognize request requires a configuration object\./);
711+
});
712+
701713
it('should find the files', function(done) {
702714
Speech.findFile_ = function(file) {
703715
assert.strictEqual(file, FILE);

0 commit comments

Comments
 (0)