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

Add error message from api request. #15657

Merged
merged 10 commits into from Jun 28, 2019
@@ -199,7 +199,7 @@ describe( 'Change detection', () => {

// Ensure save update fails and presents button.
page.waitForXPath(
'//*[contains(@class, "components-notice") and contains(@class, "is-error")]/*[text()="Updating failed"]'
'//*[contains(@class, "components-notice") and contains(@class, "is-error")]/*[text()="Updating failed. Error message: The response is not a valid JSON response."]'
),
page.waitForSelector( '.editor-post-save-draft' ),
] );
@@ -337,7 +337,7 @@ describe( 'Post generator actions', () => {
dispatch(
'core/notices',
'createErrorNotice',
...[ 'Updating failed', { id: 'SAVE_POST_NOTICE_ID' } ]
...[ 'Updating failed.', { id: 'SAVE_POST_NOTICE_ID' } ]
)
);
},
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
@@ -97,14 +97,19 @@ export function getNotificationArgumentsForSaveFail( data ) {
// If the post was being published, we show the corresponding publish error message
// Unless we publish an "updating failed" message
const messages = {
publish: __( 'Publishing failed' ),
private: __( 'Publishing failed' ),
future: __( 'Scheduling failed' ),
publish: __( 'Publishing failed.' ),
private: __( 'Publishing failed.' ),
future: __( 'Scheduling failed.' ),
};
const noticeMessage = ! isPublished && publishStatus.indexOf( edits.status ) !== -1 ?
let noticeMessage = ! isPublished && publishStatus.indexOf( edits.status ) !== -1 ?
messages[ edits.status ] :
__( 'Updating failed' );
__( 'Updating failed.' );

// Check if message string contains HTML. Notice text is currently only
// supported as plaintext, and stripping the tags may muddle the meaning.
if ( error.message && ! ( /<\/?[^>]*>/.test( error.message ) ) ) {
noticeMessage = sprintf( __( '%1$s Error message: %2$s' ), noticeMessage, error.message );

This comment has been minimized.

Copy link
@swissspidy

swissspidy Jul 1, 2019

Member

This is missing a translator comment to explain the parameters.

This comment has been minimized.

Copy link
@spacedmonkey

spacedmonkey Jul 1, 2019

Author Contributor

Should this be another PR?

This comment has been minimized.

Copy link
@swissspidy
}
return [ noticeMessage, {
id: SAVE_POST_NOTICE_ID,
} ];
@@ -93,7 +93,7 @@ describe( 'getNotificationArgumentsForSaveSuccess()', () => {
} );
} );
describe( 'getNotificationArgumentsForSaveFail()', () => {
const error = { code: '42' };
const error = { code: '42', message: 'Something went wrong.' };
const post = { status: 'publish' };
const edits = { status: 'publish' };
const defaultExpectedAction = { id: SAVE_POST_NOTICE_ID };
@@ -108,25 +108,25 @@ describe( 'getNotificationArgumentsForSaveFail()', () => {
'when post is not published and edits is published',
'',
[ 'draft', 'publish' ],
[ 'Publishing failed', defaultExpectedAction ],
[ 'Publishing failed. Error message: Something went wrong.', defaultExpectedAction ],
],
[
'when post is published and edits is privately published',
'',
[ 'draft', 'private' ],
[ 'Publishing failed', defaultExpectedAction ],
[ 'Publishing failed. Error message: Something went wrong.', defaultExpectedAction ],
],
[
'when post is published and edits is scheduled to be published',
'',
[ 'draft', 'future' ],
[ 'Scheduling failed', defaultExpectedAction ],
[ 'Scheduling failed. Error message: Something went wrong.', defaultExpectedAction ],
],
[
'when post is published and edits is published',
'',
[ 'publish', 'publish' ],
[ 'Updating failed', defaultExpectedAction ],
[ 'Updating failed. Error message: Something went wrong.', defaultExpectedAction ],
],
].forEach( ( [
description,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.