Skip to content

Commit

Permalink
Fix error handling in ImageUploader
Browse files Browse the repository at this point in the history
  • Loading branch information
tkleinke committed Apr 24, 2020
1 parent 7916947 commit 9e515fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/components/image/upload/image-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export class ImageUploader {
}

const files = ImageUploader.getFiles(event);
uploadResult.messages = uploadResult.messages.concat(this.checkForUnsupportedFileTypes(files));
const message: string[]|undefined = this.checkForUnsupportedFileTypes(files);
if (message) uploadResult.messages.push(message);

const imageFiles = files.filter(file =>
ImageUploader.supportedImageFileTypes.includes(ExtensionUtil.getExtension(file)));
Expand All @@ -86,7 +87,7 @@ export class ImageUploader {
}


private checkForUnsupportedFileTypes(files: Array<File>): string[] {
private checkForUnsupportedFileTypes(files: Array<File>): string[]|undefined {

const supportedFileTypes = ImageUploader.supportedImageFileTypes.concat(ImageUploader.supportedWorldFileTypes);
const result = ExtensionUtil.reportUnsupportedFileTypes(files, supportedFileTypes);
Expand All @@ -97,7 +98,7 @@ export class ImageUploader {
supportedFileTypes.map(extension => '.' + extension).join(', ')
];
}
return [];
return undefined;
}


Expand Down
2 changes: 1 addition & 1 deletion app/core/util/extension-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ExtensionUtil {
let result: Array<any>
= [(files.length - ExtensionUtil.getUnsupportedExts(files, supportedFileTypes).length)];
if (uniqueUnsupportedExts.length > 0) {
result.push(uniqueUnsupportedExts.join(','));
result.push(uniqueUnsupportedExts.join(', '));
}
return result;
}
Expand Down

0 comments on commit 9e515fc

Please sign in to comment.