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 Strip html tags from file upload error responses #1138

Merged

Conversation

emteknetnz
Copy link
Member

@emteknetnz emteknetnz commented Sep 15, 2020

Fixes #915

Notes

  • The max-width 50% possibly solves Error message when adding large files are not readable #895 (though it was unintentional)
  • The unused messages for "file cannot be found" and "extension is not allowed" is for the DSM which does contain messages for "file size limit exceeded" and "something went wrong, please try again"

Update transifix

  • Have pushed new translations to transifix (en.json has been updated in this PR, but not en.js)

New behaviour:

File Manager Gallery Server Error 413

image

File Manager Gallery Server Error - Non-413

image

Upload Field Error - Server Error 413

image

Upload Field Error - Server Error Non-413
image

Non Server Error file size too big messaging remains as is

image

image

Error can be simulated in File manager gallery by updating AssetAdmin.php

    public function apiCreateFile(HTTPRequest $request)
    {
        $this->httpError(413);

Error can be simulated in upload field by updating UploadField.php

    public function upload(HTTPRequest $request)
    {
        $this->httpError(413);

Add an upload field to Page.php

    class Page extends SiteTree
    {
        public function getCMSFields()
        {
            $uploadField = new UploadField('ABC');
            $fields = parent::getCMSFields();
            $fields->insertBefore('Title', $uploadField);
            return $fields;
        }

Copy link
Member

@Cheddam Cheddam left a comment

Choose a reason for hiding this comment

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

@emteknetnz The goal was to produce readable error messages for users, which I'd argue simply stripping the HTML tags does not achieve. With the example in the original issue, an author would now see:

413 Request Entity Too Large

The author might infer that this means their file was too big, but it's not exactly a clear description, and other errors may not fair as well. I think you'd be better off creating a map of HTTP error codes to author-readable messages and using those if the response is a string. If developers want to push through a custom error message, they need to make sure they return a valid JSON response with the errors key populated.

cc/ @silverstripeux - maybe you can collaborate on the error messaging?

@sachajudd
Copy link
Contributor

Linking to #895 (comment) as I've just added some designs with four different error messages that we'd like to add in an instance that an extension is not allowed or a file is too big etc. We can come up with a few more if need be but these should allow you to cover the most common errors.

@emteknetnz emteknetnz force-pushed the pulls/1.6/error-html-tags branch 3 times, most recently from eb2d484 to 4822605 Compare September 15, 2020 23:39
Copy link
Member

@Cheddam Cheddam left a comment

Choose a reason for hiding this comment

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

Looking good, one small recommended change.

client/src/lib/getStatusCodeMessage.js Show resolved Hide resolved
@Cheddam Cheddam merged commit 351405f into silverstripe:1.6 Sep 23, 2020
@Cheddam Cheddam deleted the pulls/1.6/error-html-tags branch September 23, 2020 01:53
@dhensby
Copy link
Contributor

dhensby commented Sep 23, 2020

Nice work!

blueo added a commit to blueo/silverstripe-asset-admin that referenced this pull request Aug 8, 2023
blueo added a commit to blueo/silverstripe-asset-admin that referenced this pull request Aug 8, 2023
blueo added a commit to blueo/silverstripe-asset-admin that referenced this pull request Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message from server contains extraneous markup
4 participants