Unverified Commit 0067a79e authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch Committed by Mateu Aguiló Bosch
Browse files

Issue #3314315 by e0ipso: Useful error message for disabled providers

parent a8814bf4
Loading
Loading
Loading
Loading
+9 −12
Original line number Diff line number Diff line
@@ -2,10 +2,10 @@

namespace Drupal\cl_server\Controller;

use Drupal\cl_components\Plugin\Component;
use Drupal\cl_components\ComponentPluginManager;
use Drupal\cl_components\Exception\ComponentNotFoundException;
use Drupal\cl_components\Exception\TemplateNotFoundException;
use Drupal\cl_components\Plugin\Component;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
@@ -65,19 +65,16 @@ class ServerEndpointController extends ControllerBase {
    $arguments = $this->getArguments($request);
    try {
      $component = $this->getComponent($request);
    }
    catch (ComponentNotFoundException $e) {
      throw new BadRequestHttpException('Invalid component', $e);
    }
      $variant = $request->query->get('_variant');
      // Storybook will not allow empty title for the story. Let's consider
      // Default to be the default.
      $variant = $variant === 'default' ? '' : $variant ?? '';
    try {
      $build = $this->generateRenderArray($component, $variant ?: '', $arguments);
    }
    catch (TemplateNotFoundException $e) {
      $build = [];
    catch (ComponentNotFoundException|TemplateNotFoundException $e) {
      $build = [
        '#markup' => '<div class="messages messages--error"><h3>' . $this->t('Unable to find component') . '</h3>' . $this->t('Check that the module or theme containing the component is enabled and matches the stories file name.') . '</div>',
      ];
    }
    $this->cacheKillSwitch->trigger();
    return [