Skip to content

Commit

Permalink
Updated error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBackx committed Jan 2, 2023
1 parent 99c76ed commit 29ded55
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
5 changes: 2 additions & 3 deletions ghost/admin/app/components/modal-import-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ModalComponent from 'ghost-admin/components/modal-base';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import {GENERIC_ERROR_MESSAGE} from 'ghost-admin/services/notifications';
import {computed} from '@ember/object';
import {getErrorCode, getErrorMessage} from '../services/ajax';
import {getErrorCode} from '../services/ajax';
import {inject} from 'ghost-admin/decorators/inject';
import {
isRequestEntityTooLargeError,
Expand Down Expand Up @@ -91,9 +91,8 @@ export default ModalComponent.extend({
this.notifications.showAPIError(error);
}

// First handle safe error messages, then default to more generic error messages
if (getErrorCode(error) === 'INVALID_ZIP_FILE_NAME_ENCODING') {
message = getErrorMessage(error);
message = 'The uploaded zip could not be read due to a long or invalid file name. Please remove any special characters from the file name, or alternatively try another archiving tool if using MacOS Archive Utility.';
} else if (isUnsupportedMediaTypeError(error)) {
message = 'The file type you uploaded is not supported.';
} else if (isRequestEntityTooLargeError(error)) {
Expand Down
11 changes: 0 additions & 11 deletions ghost/admin/app/services/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,6 @@ export function getErrorCode(errorOrStatus) {
return null;
}

/**
* Returns the message (from the payload) from an error object.
* @returns {string|null} error message
*/
export function getErrorMessage(errorOrStatus) {
if (isAjaxError(errorOrStatus) && errorOrStatus.payload && errorOrStatus.payload.errors && Array.isArray(errorOrStatus.payload.errors) && errorOrStatus.payload.errors.length > 0) {
return errorOrStatus.payload.errors[0].message ?? '';
}
return null;
}

/* Maintenance error */

export class MaintenanceError extends AjaxError {
Expand Down
8 changes: 5 additions & 3 deletions ghost/core/core/server/data/importer/import-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ const messages = {
invalidZipStructure: 'Invalid zip file structure.',
invalidZipFileBaseDirectory: 'Invalid zip file: base directory read failed',
zipContainsMultipleDataFormats: 'Zip file contains multiple data formats. Please split up and import separately.',
// The following error is whitelisted and shown in the frontend. It should be carefully worded.
invalidZipFileNameEncoding: 'The uploaded zip is not readable. Try re-zipping the zip with a different archiving tool (not MacOS Archive Utility) or remove the special characters from the file names.'
invalidZipFileNameEncoding: 'The uploaded zip could not be read',
invalidZipFileNameEncodingContext: 'The filename was too long or contained invalid characters',
invalidZipFileNameEncodingHelp: 'Remove any special characters from the file name, or alternatively try another archiving tool if using MacOS Archive Utility',
};

// Glob levels
Expand Down Expand Up @@ -184,7 +185,8 @@ class ImportManager {
// This causes ENAMETOOLONG error on Linux, because the resulting filename length is too long when decoded using the default string encoder.
throw new errors.UnsupportedMediaTypeError({
message: tpl(messages.invalidZipFileNameEncoding),
context: err.message,
context: tpl(messages.invalidZipFileNameEncodingContext),
help: tpl(messages.invalidZipFileNameEncodingHelp),
code: 'INVALID_ZIP_FILE_NAME_ENCODING'
});
}
Expand Down

0 comments on commit 29ded55

Please sign in to comment.