Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix handling of internal errors when uploading theming files
When a file can not be uploaded in the Theming app due to an expected
error (like an invalid mime type) the response contains a "data.message"
field. However, if the upload fails due to an unexpected error (like an
internal error, for example if the "mime_content_type" function is
disabled) there is no such field, so it should not be used.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Jul 24, 2022
commit 393c89142179454d731931e85399685237f2a1bc
3 changes: 2 additions & 1 deletion apps/theming/js/settings-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ window.addEventListener('DOMContentLoaded', function () {
},
fail: function (e, response){
var $form = $(e.target).closest('form');
OC.msg.finishedError('#theming_settings_msg', response._response.jqXHR.responseJSON.data.message);
const responseJSON = response._response.jqXHR.responseJSON;
OC.msg.finishedError('#theming_settings_msg', responseJSON && responseJSON.data && responseJSON.data.message ? responseJSON.data.message : t('theming', 'Error uploading the file'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OC.msg.finishedError('#theming_settings_msg', responseJSON && responseJSON.data && responseJSON.data.message ? responseJSON.data.message : t('theming', 'Error uploading the file'));
OC.msg.finishedError('#theming_settings_msg', responseJSON?.data?.message || t('theming', 'Error uploading the file'));

Let's shorten this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the long syntax because the JavaScript file is not transpiled. Is it safe to use the optional chaining operator in that case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Judging from the compatibility table and the supported browsers of our browserslist config it looks like everything is fully compatible except for 0.560% of users on v12.2-12.5 of Safari iOS

So for now I'd say to not use the modern syntax to ensure compatibility

$form.find('label.button').addClass('icon-upload').removeClass('icon-loading-small');
$('#theming_settings_loading').hide();
}
Expand Down