@@ -286,16 +286,23 @@ function uploadAvatar(file) {
286
286
return API . User_UploadAvatar ( { file} )
287
287
. then ( ( response ) => {
288
288
if ( response . jsonCode !== 200 ) {
289
- // Show the user feedback
290
- const errorMessage = translateLocal ( 'workspace.editor.avatarUploadFailureMessage' ) ;
291
- Growl . error ( errorMessage , 5000 ) ;
292
- return ;
289
+ // Let the component handle the issue.
290
+ throw new Error ( ) ;
293
291
}
294
292
295
293
return response . s3url ;
296
294
} ) ;
297
295
}
298
296
297
+ /**
298
+ * Sets local values for the policy
299
+ * @param {String } policyID
300
+ * @param {Object } values
301
+ */
302
+ function updateLocalPolicyValues ( policyID , values ) {
303
+ Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , values ) ;
304
+ }
305
+
299
306
/**
300
307
* Sets the name of the policy
301
308
*
@@ -307,34 +314,22 @@ function update(policyID, values, shouldGrowl = false) {
307
314
API . UpdatePolicy ( { policyID, value : JSON . stringify ( values ) , lastModified : null } )
308
315
. then ( ( policyResponse ) => {
309
316
if ( policyResponse . jsonCode !== 200 ) {
310
- // Show the user feedback
311
- const errorMessage = translateLocal ( 'workspace.editor.genericFailureMessage' ) ;
312
- Growl . error ( errorMessage , 5000 ) ;
313
- Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , { isPolicyUpdating : false } ) ;
314
- return ;
317
+ throw new Error ( ) ;
315
318
}
316
319
317
- const updatedValues = { ...values , ...{ isPolicyUpdating : false } } ;
318
- Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , updatedValues ) ;
320
+ updateLocalPolicyValues ( policyID , { ...values , isPolicyUpdating : false } ) ;
319
321
if ( shouldGrowl ) {
320
322
Growl . show ( translateLocal ( 'workspace.common.growlMessageOnSave' ) , CONST . GROWL . SUCCESS , 3000 ) ;
321
323
}
322
324
} ) . catch ( ( ) => {
323
- Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , { isPolicyUpdating : false } ) ;
325
+ updateLocalPolicyValues ( policyID , { isPolicyUpdating : false } ) ;
326
+
327
+ // Show the user feedback
324
328
const errorMessage = translateLocal ( 'workspace.editor.genericFailureMessage' ) ;
325
329
Growl . error ( errorMessage , 5000 ) ;
326
330
} ) ;
327
331
}
328
332
329
- /**
330
- * Sets local values for the policy
331
- * @param {String } policyID
332
- * @param {Object } values
333
- */
334
- function updateLocalPolicyValues ( policyID , values ) {
335
- Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , values ) ;
336
- }
337
-
338
333
/**
339
334
* @param {String } policyID
340
335
* @param {Object } errors
0 commit comments