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;
} // Extract the form AJAX exception (it may have been passed to another
// exception before reaching here).
if ($exception =
$this->
getFormAjaxException($exception)) {