All files / mobile.editor.overlay saveFailureMessage.js

11.11% Statements 1/9
0% Branches 0/12
0% Functions 0/1
11.11% Lines 1/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30            1x                                              
/**
 * Build a save failure message from the API response
 *
 * @param {Object} data API response
 * @return {string} message HTML text describing the failure for display to the user
 */
module.exports = function saveFailureMessage( data ) {
	// In most cases, return the error message from the API directly.
	// Handle a few exceptions where it is unsuitable for end-users
	// (some error messages are seemingly intended for tool developers).
 
	var code = data && data.errors && data.errors[0] && data.errors[0].code;
 
	if ( code === 'editconflict' ) {
		return mw.msg( 'mobile-frontend-editor-error-conflict' );
	}
 
	if ( code === 'readonly' ) {
		return data.errors[0].html + '<br>' + data.errors[0].data.readonlyreason;
	}
 
	if ( data.errors && data.errors[0] ) {
		return data.errors[0].html;
	}
 
	// This probably indicates a connection problem and a "fake" response
	// generated by mediawiki.Api. TODO Give a better error message here.
	return '';
};