Skip to content

Alerts don't show on non-node pages, and log an error on 404s #168

@andriokha

Description

@andriokha

I noticed the following in our production watchdog logs:

Symfony\Component\Routing\Exception\ResourceNotFoundException: No routes found for "/alerts". in Drupal\Core\Routing\Router->matchRequest() (line 150 of /code/web/core/lib/Drupal/Core/Routing/Router.php).

After a bit of debugging I realized the issue wasn't with the route /alerts but with the match made from within the rest resource shown below, that doesn't catch the exceptions that might be thrown by \Symfony\Component\Routing\Matcher\RequestMatcherInterface::matchRequest():

$result = $this->router->match($uri);
if (!isset($result['node'])) {
return new ModifiedResourceResponse('Node not found');
}

I can recreate the issue locally by adding an alert and visiting a URL that issues a 404. Looking at the code, it seemed like the lack of a node would prevent an alert showing up, so I tried visiting a webform at its form/FORM_ID URL and then visited a route provided by a custom controller. It seems that in these circumstances alerts don't show up. And if you inspect the response of the fetch request you can see the text Node not found.

Proposed resolution

  1. Alerts shouldn't be constrained to node pages.
  2. Visiting a 404 shouldn't cause an uncaught exception from within the custom rest resource.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions