contao / core-bundle

[READ-ONLY] Contao Core Bundle
GNU Lesser General Public License v3.0
123 stars 58 forks source link

DropZone cannot handle errors #1506

Closed fritzmg closed 6 years ago

fritzmg commented 6 years ago

If $this->blnHasError is set to true for Contao\DropZone during uploadTo(…) for example, there will simply be a 500 response and the error will not be visible in the DropZone. Instead it will show the following:

dropzone-error

In this example I simulated a file with an invalid file name that would trigger

// Invalid file name
if (!\Validator::isValidFileName($file['name']))
{
    \Message::addError($GLOBALS['TL_LANG']['ERR']['filename']);
    $this->blnHasError = true;
}

within FileUpload::uploadTo. This can be fixed by adding

    // Redirect or reload
    if (!$objUploader->hasError())
    {
        if ($blnIsAjax)
        {
            throw new ResponseException(new Response(\Message::generateUnwrapped(), 201));
        }

        // Do not purge the html folder (see #2898)
        if (isset($_POST['uploadNback']) && !$objUploader->hasResized())
        {
            \Message::reset();
            $this->redirect($this->getReferer());
        }

        $this->reload();
    }
+   elseif ($blnIsAjax)
+   {
+       throw new ResponseException(new Response(\Message::generateUnwrapped(), 500));
+   }

in DC_Folder::move. However, then it will still look like this:

dropzone-error-2

Since the Message class automatically wraps the messages with HTML and DropZone expects the server response to be pure text.

leofeyer commented 6 years ago

See #1509.