@@ -210,7 +210,6 @@ class Model extends Entity {
210210 const _this = this ;
211211
212212 let entityUpdated ;
213- let error = { } ;
214213
215214 const key = this . key ( id , ancestors , namespace ) ;
216215 const replace = options && options . replace === true ;
@@ -223,7 +222,8 @@ class Model extends Entity {
223222 */
224223 if ( replace ) {
225224 return saveEntity ( { key, data } )
226- . then ( onEntityUpdated , onUpdateError ) ;
225+ . then ( onEntityUpdated )
226+ . catch ( onUpdateError ) ;
227227 }
228228
229229 if ( typeof transaction === 'undefined' || transaction === null ) {
@@ -232,22 +232,21 @@ class Model extends Entity {
232232 return transaction
233233 . run ( )
234234 . then ( getAndUpdate )
235- . catch ( onTransactionError ) ;
235+ . catch ( onUpdateError ) ;
236236 }
237237
238238 if ( transaction . constructor . name !== 'Transaction' ) {
239239 return Promise . reject ( new Error ( 'Transaction needs to be a gcloud Transaction' ) ) ;
240240 }
241241
242- return getAndUpdate ( )
243- . catch ( onTransactionError ) ;
242+ return getAndUpdate ( ) ;
244243
245244 // ---------------------------------------------------------
246245
247246 function getAndUpdate ( ) {
248247 return getEntity ( )
249248 . then ( saveEntity )
250- . then ( onEntityUpdated , onUpdateError ) ;
249+ . then ( onEntityUpdated ) ;
251250 }
252251
253252 function getEntity ( ) {
@@ -257,11 +256,10 @@ class Model extends Entity {
257256 const entity = getData [ 0 ] ;
258257
259258 if ( typeof entity === 'undefined' ) {
260- error = new GstoreError (
259+ throw ( new GstoreError (
261260 errorCodes . ERR_ENTITY_NOT_FOUND ,
262261 `Entity { ${ id . toString ( ) } } to update not found`
263- ) ;
264- throw ( error ) ;
262+ ) ) ;
265263 }
266264
267265 extend ( false , entity , data ) ;
@@ -272,10 +270,6 @@ class Model extends Entity {
272270 } ;
273271
274272 return result ;
275- } )
276- . catch ( err => {
277- error = err ;
278- return err ;
279273 } ) ;
280274 }
281275
@@ -319,14 +313,16 @@ class Model extends Entity {
319313 }
320314
321315 function onUpdateError ( err ) {
322- error = err ;
316+ const error = Array . isArray ( err ) ? err [ 0 ] : err ;
323317 if ( internalTransaction ) {
324318 // If we created the Transaction instance internally for the update, we rollback it
325319 // otherwise we leave the rollback() call to the transaction creator
326- return transaction . rollback ( ) . then ( ( ) => onTransactionError ( [ err ] ) ) ;
320+ return transaction . rollback ( ) . then ( ( ) => {
321+ throw error ;
322+ } ) ;
327323 }
328324
329- return onTransactionError ( [ err ] ) ;
325+ throw error ;
330326 }
331327
332328 function onTransactionSuccess ( ) {
@@ -349,14 +345,6 @@ class Model extends Entity {
349345
350346 return entityUpdated ;
351347 }
352-
353- function onTransactionError ( transactionError = { } ) {
354- const apiResponse = transactionError && Array . isArray ( transactionError )
355- ? transactionError [ 0 ]
356- : transactionError ;
357- extend ( apiResponse , transactionError ) ;
358- throw apiResponse ;
359- }
360348 }
361349
362350 static delete ( id , ancestors , namespace , transaction , key , options = { } ) {
0 commit comments