Return 404 for invalid routes
See original GitHub issueCurrently, any request which doesn’t match a route causes an error-level log event. HTTP requests are mapped to the usual Django 404 path but websockets cause a traceback like this:
$ pipenv run daphne -p 8001 inventory.asgi:application
Loading .env environment variables…
[2018-02-07 20:04:12] botocore.credentials INFO Found credentials in shared credentials file: ~/.aws/credentials
[2018-02-07 20:04:12] daphne.cli INFO Starting server at tcp:port=8001:interface=127.0.0.1
[2018-02-07 20:04:12] daphne.server INFO HTTP/2 support not enabled (install the http2 and tls Twisted extras)
[2018-02-07 20:04:12] daphne.server INFO Listening on endpoint tcp:port=8001:interface=127.0.0.1
[2018-02-07 20:04:28] daphne.ws_protocol ERROR Traceback (most recent call last):
File "/Users/cadams/.virtualenvs/inventory-api-prototype-yJheR8NE/lib/python3.6/site-packages/daphne/ws_protocol.py", line 76, in onConnect
"subprotocols": subprotocols,
File "/Users/cadams/.virtualenvs/inventory-api-prototype-yJheR8NE/lib/python3.6/site-packages/daphne/server.py", line 177, in create_application
application_instance = self.application(scope=scope)
File "/Users/cadams/.virtualenvs/inventory-api-prototype-yJheR8NE/lib/python3.6/site-packages/channels/routing.py", line 51, in __call__
return self.application_mapping[scope["type"]](scope)
File "/Users/cadams/.virtualenvs/inventory-api-prototype-yJheR8NE/lib/python3.6/site-packages/channels/routing.py", line 89, in __call__
raise ValueError("No route found for path %r." % path)
ValueError: No route found for path 'foo/bar'.
$ wst client ws://localhost:8001/foo/bar
Client closed connection (Abnormal)
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Return 404 for invalid routes via nginx
In that case i want to throw 404 without landing to application at nginx level itself. Is this possible to handle routing at...
Read more >How To Properly Serve 404 Errors on SPAs (with SEO ...
Out of the box, 404 error pages in SPAs don't work properly, creating problems for SEO. Here we'll review the pros and cons...
Read more >Handling 404 Not Found in Asp.Net Core - DevTrends
This is where the URL matches a route but one or more parameter is invalid. We can address this with a custom view....
Read more >How to wrap a route not found exception with the generic ...
The status code 404 is also added to the response when the resource is not found, like when Id is not found or...
Read more >404 page instead of {METHOD} not supported for this route
It sounds like the order of your routes might cause this. If you have for example first a route 'products/{product}' followed by a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve end up with below code:
middleware.py
asgi.py
My environment:
Python 3.8.6 django 3.1.7 channels 3.0.3 daphne 3.0.1
@acdha I got this issue from sentry many times, so I write middleware for handling it. I hope it’s the right way to handle this problem If any good idea please let me know, thanks.