Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error message upon trashing failure #1857

Merged
merged 2 commits into from
Jul 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -147,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;
Expand Down