Skip to content

Commit

Permalink
Feature: Allow custom message on upload error
Browse files Browse the repository at this point in the history
  • Loading branch information
emerilek committed Apr 28, 2024
1 parent 25d46cd commit 4b349ce
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ export default class ImageTool {
if (response.success && response.file) {
this.image = response.file;
} else {
this.uploadingFailed('incorrect response: ' + JSON.stringify(response));
const customErrorMessage = typeof response.message === 'string' ? response.message : undefined;
this.uploadingFailed('incorrect response: ' + JSON.stringify(response), customErrorMessage);
}
}

Expand All @@ -408,13 +409,14 @@ export default class ImageTool {
*
* @private
* @param {string} errorText - uploading error text
* @param {string | undefined} customErrorText - displayed error text
* @returns {void}
*/
uploadingFailed(errorText) {
uploadingFailed(errorText, customErrorText) {
console.log('Image Tool: uploading failed because of', errorText);

this.api.notifier.show({
message: this.api.i18n.t('Couldn’t upload image. Please try another.'),
message: customErrorText ?? this.api.i18n.t('Couldn’t upload image. Please try another.'),
style: 'error',
});
this.ui.hidePreloader();
Expand Down

0 comments on commit 4b349ce

Please sign in to comment.