From 069975c5fb5b649fa8e7822c8c822db5f336b6d9 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sat, 8 Jul 2017 13:40:31 -0700 Subject: [PATCH 1/2] Show error message upon trashing failure --- editor/effects.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/editor/effects.js b/editor/effects.js index 948c8ead3163cd..c6bb6da95ef57d 100644 --- a/editor/effects.js +++ b/editor/effects.js @@ -83,7 +83,7 @@ export default { const messages = { publish: __( 'Post published!' ), 'private': __( 'Post published privately!' ), - future: __( 'Post schduled!' ), + future: __( 'Post scheduled!' ), }; // If we save a non published post, we don't show any notice @@ -132,12 +132,31 @@ export default { const { dispatch, getState } = store; const { postId } = action; const Model = wp.api.getPostTypeModel( getCurrentPostType( getState() ) ); - new Model( { id: postId } ).destroy().done( () => { - dispatch( { - ...action, - type: 'TRASH_POST_SUCCESS', - } ); - } ); + new Model( { id: postId } ).destroy().then( + () => { + dispatch( { + ...action, + type: 'TRASH_POST_SUCCESS', + } ); + }, + ( err ) => { + dispatch( { + ...action, + type: 'TRASH_POST_FAILURE', + error: get( err, 'responseJSON', { + code: 'unknown_error', + message: __( 'An unknown error occurred.' ), + } ), + } ); + let message; + if ( err.responseJSON && err.responseJSON.message ) { + message = err.responseJSON.message; + } else { + message = __( 'Trashing failed' ); + } + dispatch( errorNotice( message ) ); + } + ); }, TRASH_POST_SUCCESS( action ) { const { postId, postType } = action; From b05129aa305faf4090d088080b6c445b0680a096 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 13 Jul 2017 13:14:37 -0700 Subject: [PATCH 2/2] Add TRASH_POST_FAILURE effect for dispatching trash error message --- editor/effects.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/editor/effects.js b/editor/effects.js index c6bb6da95ef57d..96a9cd42a7f2df 100644 --- a/editor/effects.js +++ b/editor/effects.js @@ -148,13 +148,6 @@ export default { message: __( 'An unknown error occurred.' ), } ), } ); - let message; - if ( err.responseJSON && err.responseJSON.message ) { - message = err.responseJSON.message; - } else { - message = __( 'Trashing failed' ); - } - dispatch( errorNotice( message ) ); } ); }, @@ -166,6 +159,10 @@ export default { ids: postId, } ); }, + TRASH_POST_FAILURE( action, store ) { + const message = action.error.message && action.error.code !== 'unknown_error' ? action.error.message : __( 'Trashing failed' ); + store.dispatch( errorNotice( message ) ); + }, MERGE_BLOCKS( action, store ) { const { dispatch } = store; const [ blockA, blockB ] = action.blocks;