-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix handling of internal errors when uploading theming files #33332
Fix handling of internal errors when uploading theming files #33332
Conversation
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 <danxuliu@gmail.com>
/backport to stable24 |
/backport to stable23 |
@@ -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')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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 themime_content_type
function is disabled) there is no such field, so it should not be used.How to test
throw new \Exception();
toThemingController::updateImage
Result with this pull request
Error uploading the file is shown and the spinner on the upload button is replaced again with the upload icon
Result without this pull request
No error message is shown and the spinner on the upload button never ends