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

Update file upload so that it has better error support. #8427

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ianwallen
Copy link
Contributor

@ianwallen ianwallen commented Oct 13, 2024

  • Add bilingual error message.
  • Fix queue removal so that it only remove items that are complete instead of fully clearing the queue.
  • Fix error message Uncaught TypeError: Cannot read properties of undefined (reading 'message')
  • Catch status 0 which is generally a network error and display an error message
  • Catch status 413 which may come from a proxy server with no messages - it now displays correct error message.
  • Add humanizeFileSize so that users can see errors in nice format instead of long byte format.

Before

image

After

image

If the proxy such as nginx returns 413 File too large then the following is displayed

image

And if the upload times out or connection is closed while uploading then the following will be displayed.

image

Checklist

  • I have read the contribution guidelines
  • Pull request provided for main branch, backports managed with label
  • Good housekeeping of code, cleaning up comments, tests, and documentation
  • Clean commit history broken into understandable chucks, avoiding big commits with hundreds of files, cautious of reformatting and whitespace changes
  • Clean commit messages, longer verbose messages are encouraged
  • API Changes are identified in commit messages
  • Testing provided for features or enhancements using automatic tests
  • User documentation provided for new features or enhancements in manual
  • Build documentation provided for development instructions in README.md files
  • Library management using pom.xml dependency management. Update build documentation with intended library use and library tutorials or documentation

@ianwallen ianwallen added this to the 4.4.6 milestone Oct 13, 2024
@@ -80,4 +80,14 @@ public static String readLastLines(File file, int lines) {
}
}
}

public static String humanizeFileSize(long bytes) {
Copy link
Member

Choose a reason for hiding this comment

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

Check if could be used: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#byteCountToDisplaySize(long).

But I see that it's implemented in Javascript a similar function, so probably good to keep them aligned.

The calculation doesn't seem accurate, the original exception message is Maximum upload size of 100000000 bytes exceeded

error

Also the message looks not good: Payload Too LargeMaximum upload size...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added javadocs explaining that this was mostly picked due to the extra decimal places.

If we don't want to support new code and prefer to round to the nearest MB then I'm fine with removing this and using the apache commons version.

Regarding the error message, this seems to be caused by the data.errorThrown being prepended to the error message. Since we translate the other messages we probably don't want to add non translated and translated text at the same time so I moved the assignment of data.errorThrown at the end only in cases where the message was still empty. This should soft your issue.

public ApiError maxFileExceededHandler(final Exception exception, final HttpServletRequest request) {
Exception ex;
long contentLength = request.getContentLengthLong();
// As MaxUploadSizeExceededException is a sping exception, we need to convert it to a localized exception so that it can be translated.
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
// As MaxUploadSizeExceededException is a sping exception, we need to convert it to a localized exception so that it can be translated.
// As MaxUploadSizeExceededException is a Spring exception, we need to convert it to a localized exception so that it can be translated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -91,30 +91,76 @@
}
});

var humanizeDataSize = function (bytes) {
Copy link
Member

Choose a reason for hiding this comment

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

You need to build the project with mvn clean install, so Prettier formatting is applied to Javascript files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand this comment? Are you implying that most developers will not do a mvn clean install?

Copy link
Member

Choose a reason for hiding this comment

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

@ianwallen if you build the project locally you should see web-ui/src/main/resources/catalog/components/filestore/FileStoreDirective.js with changes due to Prettier maven plugin.

It seems some changes have been done in the file after doing a mvn install.

You just need to run that and commit the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK - I understand -I have pushed the pretty print changes.

- Add bilingual error message.
- Fix queue removal so that it only remove items that are complete instead of fully clearing the queue.
- Fix error message Uncaught TypeError: Cannot read properties of undefined (reading 'message')
- Catch status 0 which is generally a network error and display an error message
- Catch status 413 which may come from a proxy server with no messages - it now displays correct error message.
- Add humanizeFileSize so that users can see errors in nice format instead of long byte format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants