Skip to content
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

Conversation

danxuliu
Copy link
Member

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.

How to test

  • For simplicity, just force an internal error by adding throw new \Exception(); to ThemingController::updateImage
  • Log in to Nextcloud as an admin
  • Open the Theming section in the Adminstration settings
  • Upload a logo

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

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>
@danxuliu danxuliu added this to the Nextcloud 25 milestone Jul 24, 2022
@danxuliu
Copy link
Member Author

/backport to stable24

@danxuliu
Copy link
Member Author

/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'));
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

@skjnldsv skjnldsv mentioned this pull request Aug 18, 2022
This was referenced Aug 24, 2022
Copy link
Member

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants