Ajax throws the wrong error when failed

Created on 3 April 2023, about 1 year ago
Updated 25 April 2024, 2 months ago

Problem/Motivation

When an Ajax petition failed the error thrown is "An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports." https://git.drupalcode.org/project/drupal/-/blob/cbd9cc885e558c692636778...

  public function onException(ExceptionEvent $event) {
    $exception = $event->getThrowable();
    $request = $event->getRequest();

    // Render a nice error message in case we have a file upload which exceeds
    // the configured upload limit.
    if ($exception instanceof BrokenPostRequestException && $request->query->has(FormBuilderInterface::AJAX_FORM_REQUEST)) {
      $this->messenger->addError($this->t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', ['@size' => $this->formatSize($exception->getSize())]));
      $response = new AjaxResponse(NULL, 200);
      $status_messages = ['#type' => 'status_messages'];
      $response->addCommand(new PrependCommand(NULL, $status_messages));
      $event->allowCustomResponseCode();
      $event->setResponse($response);
      return;
    }

This error is thrown on the Formbuilder https://git.drupalcode.org/project/drupal/-/blob/747b0eb6f7af6de240c3c1e...

    // In case the post request exceeds the configured allowed size
    // (post_max_size), the post request is potentially broken. Add some
    // protection against that and at the same time have a nice error message.
    if ($ajax_form_request && !$request->request->has('form_id')) {
      throw new BrokenPostRequestException($this->getFileUploadMaxSize());
    }

What is the relation of do not have the form_id set with the filesize?

I tried to understand it on https://www.drupal.org/project/drupal/issues/2500527 β†’ , but I couldn't

πŸ› Bug report
Status

Closed: duplicate

Version

11.0 πŸ”₯

Component
AjaxΒ  β†’

Last updated about 9 hours ago

Created by

πŸ‡ͺπŸ‡ΈSpain Eduardo Morales Alberti Spain, πŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024