@@ -241,10 +241,6 @@ GrpcService.prototype.request = function(protoOpts, reqOpts, callback) {
241241 return ;
242242 }
243243
244- // Clean up gcloud-specific options.
245- delete reqOpts . autoPaginate ;
246- delete reqOpts . autoPaginateVal ;
247-
248244 var service = this . getService_ ( protoOpts ) ;
249245
250246 var metadata = this . grpcMetadata ;
@@ -254,6 +250,13 @@ GrpcService.prototype.request = function(protoOpts, reqOpts, callback) {
254250 grpcOpts . deadline = GrpcService . createDeadline_ ( protoOpts . timeout ) ;
255251 }
256252
253+ try {
254+ reqOpts = util . decorateRequest ( reqOpts , { projectId : self . projectId } ) ;
255+ } catch ( e ) {
256+ callback ( e ) ;
257+ return ;
258+ }
259+
257260 // Retains a reference to an error from the response. If the final callback is
258261 // executed with this as the "response", we return it to the user as an error.
259262 var respError ;
@@ -269,13 +272,6 @@ GrpcService.prototype.request = function(protoOpts, reqOpts, callback) {
269272 request : function ( _ , onResponse ) {
270273 respError = null ;
271274
272- try {
273- reqOpts = util . decorateRequest ( reqOpts , { projectId : self . projectId } ) ;
274- } catch ( e ) {
275- onResponse ( e ) ;
276- return ;
277- }
278-
279275 service [ protoOpts . method ] ( reqOpts , metadata , grpcOpts , function ( e , resp ) {
280276 if ( e ) {
281277 respError = GrpcService . decorateError_ ( e ) ;
@@ -342,17 +338,7 @@ GrpcService.prototype.requestStream = function(protoOpts, reqOpts) {
342338 return stream ;
343339 }
344340
345- try {
346- reqOpts = util . decorateRequest ( reqOpts , { projectId : this . projectId } ) ;
347- } catch ( e ) {
348- setImmediate ( function ( ) {
349- stream . destroy ( e ) ;
350- } ) ;
351- return stream ;
352- }
353-
354341 var objectMode = ! ! reqOpts . objectMode ;
355- delete reqOpts . objectMode ;
356342
357343 var service = this . getService_ ( protoOpts ) ;
358344 var grpcOpts = { } ;
@@ -361,6 +347,15 @@ GrpcService.prototype.requestStream = function(protoOpts, reqOpts) {
361347 grpcOpts . deadline = GrpcService . createDeadline_ ( protoOpts . timeout ) ;
362348 }
363349
350+ try {
351+ reqOpts = util . decorateRequest ( reqOpts , { projectId : this . projectId } ) ;
352+ } catch ( e ) {
353+ setImmediate ( function ( ) {
354+ stream . destroy ( e ) ;
355+ } ) ;
356+ return stream ;
357+ }
358+
364359 var retryOpts = {
365360 retries : this . maxRetries ,
366361 objectMode : objectMode ,
0 commit comments