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 606c497
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default class ImageTool {
// @see https://github.com/editor-js/image/pull/49
const tunes = ImageTool.tunes.concat(this.config.actions);

return tunes.map(tune => ({
return tunes.map((tune) => ({
icon: tune.icon,
label: this.api.i18n.t(tune.title),
name: tune.name,
Expand Down Expand Up @@ -290,7 +290,7 @@ export default class ImageTool {
* Drag n drop file from into the Editor
*/
files: {
mimeTypes: [ 'image/*' ],
mimeTypes: ['image/*'],
},
};
}
Expand Down 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 Expand Up @@ -449,10 +451,11 @@ export default class ImageTool {
/**
* Wait until the API is ready
*/
Promise.resolve().then(() => {
this.block.stretched = value;
})
.catch(err => {
Promise.resolve()
.then(() => {
this.block.stretched = value;
})
.catch((err) => {
console.error(err);
});
}
Expand Down

0 comments on commit 606c497

Please sign in to comment.