Debugging errors in the backend
See original GitHub issueHello, firstly I want to say thank you because I find this project very useful! I was finding it difficult to debug some errors in a project that I’m working on, so I subclassed the middleware to return errors to the frontend like this:
import traceback
from django.conf import settings
from django.http import HttpResponse
from django_htmx.middleware import HtmxMiddleware
class HtmxDebugMiddleware(HtmxMiddleware):
def process_exception(self, request, exception):
if request.htmx and settings.DEBUG:
content = (
"<h1>Django HTMX Error</h1><b>%s</b>"
"<h3>Traceback</h3><textarea rows=10>%s</textarea>"
) % (
exception,
traceback.format_exc(),
)
return HttpResponse(content, status=200)
return None
Here is an example of what the solution above produces when raise RuntimeError("Something bad happened on the backend!")
is encountered:
Would it be desirable to include something similar in this project?
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Debugging web applications - backend
Debugging web applications - backend ; Input processing errors. HTTP protocol debugging ; Data retrieval errors · SQL query debugging ; Template related...
Read more >Web API Error Handling: How To Make Debugging Easier
Whether you're the consumer or producer of an API, you've no doubt seen that good error handling can make debugging easier.
Read more >How to Debug Your Code - Codecademy
Another method of debugging your code is using error handling. Code that does not use error handling will often crash when it encounters...
Read more >How to debug front-end or back-end issues (must have)?
How to debug front-end or back-end issues (must have)? by Denis Platonov, Co-founder of Test ProStart for free: ...
Read more >4. Error Handling and Debugging - VBScript in a Nutshell [Book]
Debugging , on the other hand, involves finding errors and removing them from your program. There are many types of errors that you...
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 FreeTop 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
Top GitHub Comments
Just released in version 1.2.0 - check it out!
Ah good, my misunderstanding… I’ve just seen too many people running debug mode in prod 😅
Yes this is true. I’m not sure there’s much we can do about that. Thankfully most pages should be fairly deterministic in the order that errors occur.