Skip to content

Commit

Permalink
Merge pull request #1857 from WordPress/add/trash-failure-message
Browse files Browse the repository at this point in the history
Show error message upon trashing failure
  • Loading branch information
westonruter authored Jul 13, 2017
2 parents af63d4e + b05129a commit ffe4ab8
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions editor/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,12 +132,24 @@ 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.' ),
} ),
} );
}
);
},
TRASH_POST_SUCCESS( action ) {
const { postId, postType } = action;
Expand All @@ -151,6 +163,10 @@ export default {
} );
} );
},
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;
Expand Down

0 comments on commit ffe4ab8

Please sign in to comment.