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
- Alerts shouldn't be constrained to node pages.
- Visiting a 404 shouldn't cause an uncaught exception from within the custom rest resource.
Thanks!
I noticed the following in our production watchdog logs:
After a bit of debugging I realized the issue wasn't with the route
/alertsbut 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():openy_node_alert/src/Plugin/rest/resource/AlertsRestResource.php
Lines 237 to 240 in d70b5a4
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_IDURL 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 textNode not found.Proposed resolution
Thanks!