Skip to content

Display error notice instead of Exception text default for Customer edition

I want to display the error notice when a specific rule match when we edit the customer informations on backend. I tried with default Exception class or Magento specific but it show the error as text page instead of the red notice usually used.
Ideally, I wish to display the red notice with a custom message (Address street has to be less or equal to 35 characters).

1 exception(s):
Exception #0 (Exception): Address street has to be less or equal to 35 characters.

Exception #0 (Exception): Address street has to be less or equal to 35 characters.
<pre>#1 MagentoCustomerControllerAdminhtmlIndexSaveInterceptor->MagentoFrameworkInterception{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#2 MagentoCustomerControllerAdminhtmlIndexSaveInterceptor->___callPlugins() called at [generated/code/Magento/Customer/Controller/Adminhtml/Index/Save/Interceptor.php:26]
#3 MagentoCustomerControllerAdminhtmlIndexSaveInterceptor->execute() called at [vendor/magento/framework/App/Action/Action.php:107]
#4 MagentoFrameworkAppActionAction->dispatch() called at [vendor/magento/module-backend/App/AbstractAction.php:235]
#5 MagentoBackendAppAbstractAction->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#6 MagentoCustomerControllerAdminhtmlIndexSaveInterceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#7 MagentoCustomerControllerAdminhtmlIndexSaveInterceptor->MagentoFrameworkInterception{closure}() called at [vendor/magento/module-backend/App/Action/Plugin/Authentication.php:143]
#8 MagentoBackendAppActionPluginAuthentication->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#9 MagentoCustomerControllerAdminhtmlIndexSaveInterceptor->MagentoFrameworkInterception{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#10 MagentoCustomerControllerAdminhtmlIndexSaveInterceptor->___callPlugins() called at [generated/code/Magento/Customer/Controller/Adminhtml/Index/Save/Interceptor.php:39]
#11 MagentoCustomerControllerAdminhtmlIndexSaveInterceptor->dispatch() called at [vendor/magento/framework/App/FrontController.php:55]
#12 MagentoFrameworkAppFrontController->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#13 MagentoFrameworkAppFrontControllerInterceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#14 MagentoFrameworkAppFrontControllerInterceptor->MagentoFrameworkInterception{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#15 MagentoFrameworkAppFrontControllerInterceptor->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.php:26]
#16 MagentoFrameworkAppFrontControllerInterceptor->dispatch() called at [vendor/magento/framework/App/Http.php:136]
#17 MagentoFrameworkAppHttp->launch() called at [vendor/magento/framework/App/Bootstrap.php:257]
#18 MagentoFrameworkAppBootstrap->run() called at [pub/index.php:37]
</pre>

Thanks in advance!

ps: Late merry Christmas and early happy new year!